@@ -275,6 +275,7 @@ public void LoadPlan(string planXml, string label, string? queryText = null)
275275
276276 _currentPlan = ShowPlanParser . Parse ( planXml ) ;
277277 PlanAnalyzer . Analyze ( _currentPlan , ConfigLoader . Load ( ) ) ;
278+ BenefitScorer . Score ( _currentPlan ) ;
278279
279280 var allStatements = _currentPlan . Batches
280281 . SelectMany ( b => b . Statements )
@@ -1725,14 +1726,21 @@ private void ShowPropertiesPanel(PlanNode node)
17251726 if ( s . PlanWarnings . Count > 0 )
17261727 {
17271728 var planWarningsPanel = new StackPanel ( ) ;
1728- foreach ( var w in s . PlanWarnings )
1729+ var sortedPlanWarnings = s . PlanWarnings
1730+ . OrderByDescending ( w => w . MaxBenefitPercent ?? - 1 )
1731+ . ThenByDescending ( w => w . Severity )
1732+ . ThenBy ( w => w . WarningType ) ;
1733+ foreach ( var w in sortedPlanWarnings )
17291734 {
17301735 var warnColor = w . Severity == PlanWarningSeverity . Critical ? "#E57373"
17311736 : w . Severity == PlanWarningSeverity . Warning ? "#FFB347" : "#6BB5FF" ;
17321737 var warnPanel = new StackPanel { Margin = new Thickness ( 10 , 2 , 10 , 2 ) } ;
1738+ var planWarnHeader = w . MaxBenefitPercent . HasValue
1739+ ? $ "\u26A0 { w . WarningType } \u2014 up to { w . MaxBenefitPercent : N0} % benefit"
1740+ : $ "\u26A0 { w . WarningType } ";
17331741 warnPanel . Children . Add ( new TextBlock
17341742 {
1735- Text = $ " \u26A0 { w . WarningType } " ,
1743+ Text = planWarnHeader ,
17361744 FontWeight = FontWeight . SemiBold ,
17371745 FontSize = 11 ,
17381746 Foreground = new SolidColorBrush ( Color . Parse ( warnColor ) )
@@ -1788,14 +1796,21 @@ private void ShowPropertiesPanel(PlanNode node)
17881796 if ( node . HasWarnings )
17891797 {
17901798 var warningsPanel = new StackPanel ( ) ;
1791- foreach ( var w in node . Warnings )
1799+ var sortedNodeWarnings = node . Warnings
1800+ . OrderByDescending ( w => w . MaxBenefitPercent ?? - 1 )
1801+ . ThenByDescending ( w => w . Severity )
1802+ . ThenBy ( w => w . WarningType ) ;
1803+ foreach ( var w in sortedNodeWarnings )
17921804 {
17931805 var warnColor = w . Severity == PlanWarningSeverity . Critical ? "#E57373"
17941806 : w . Severity == PlanWarningSeverity . Warning ? "#FFB347" : "#6BB5FF" ;
17951807 var warnPanel = new StackPanel { Margin = new Thickness ( 10 , 2 , 10 , 2 ) } ;
1808+ var nodeWarnHeader = w . MaxBenefitPercent . HasValue
1809+ ? $ "\u26A0 { w . WarningType } \u2014 up to { w . MaxBenefitPercent : N0} % benefit"
1810+ : $ "\u26A0 { w . WarningType } ";
17961811 warnPanel . Children . Add ( new TextBlock
17971812 {
1798- Text = $ " \u26A0 { w . WarningType } " ,
1813+ Text = nodeWarnHeader ,
17991814 FontWeight = FontWeight . SemiBold ,
18001815 FontSize = 11 ,
18011816 Foreground = new SolidColorBrush ( Color . Parse ( warnColor ) )
@@ -2140,18 +2155,21 @@ private object BuildNodeTooltipContent(PlanNode node, List<PlanWarning>? allWarn
21402155
21412156 if ( allWarnings != null )
21422157 {
2143- // Root node: show distinct warning type names only
2158+ // Root node: show distinct warning type names only, sorted by max benefit
21442159 var distinct = warnings
21452160 . GroupBy ( w => w . WarningType )
2146- . Select ( g => ( Type : g . Key , MaxSeverity : g . Max ( w => w . Severity ) , Count : g . Count ( ) ) )
2147- . OrderByDescending ( g => g . MaxSeverity )
2161+ . Select ( g => ( Type : g . Key , MaxSeverity : g . Max ( w => w . Severity ) , Count : g . Count ( ) ,
2162+ MaxBenefit : g . Max ( w => w . MaxBenefitPercent ?? - 1 ) ) )
2163+ . OrderByDescending ( g => g . MaxBenefit )
2164+ . ThenByDescending ( g => g . MaxSeverity )
21482165 . ThenBy ( g => g . Type ) ;
21492166
2150- foreach ( var ( type , severity , count ) in distinct )
2167+ foreach ( var ( type , severity , count , maxBenefit ) in distinct )
21512168 {
21522169 var warnColor = severity == PlanWarningSeverity . Critical ? "#E57373"
21532170 : severity == PlanWarningSeverity . Warning ? "#FFB347" : "#6BB5FF" ;
2154- var label = count > 1 ? $ "\u26A0 { type } ({ count } )" : $ "\u26A0 { type } ";
2171+ var benefitSuffix = maxBenefit >= 0 ? $ " \u2014 up to { maxBenefit : N0} %" : "" ;
2172+ var label = count > 1 ? $ "\u26A0 { type } ({ count } ){ benefitSuffix } " : $ "\u26A0 { type } { benefitSuffix } ";
21552173 stack . Children . Add ( new TextBlock
21562174 {
21572175 Text = label ,
0 commit comments