@@ -426,7 +426,22 @@ BEGIN
426426 SELECT REPLICATE (' -' , 100 ) UNION ALL
427427 SELECT ' volatile_metrics: flags metrics with extreme variance: (max - min) / avg > 10x.' UNION ALL
428428 SELECT ' Only flagged when the absolute max exceeds meaningful thresholds (1s duration, 100ms CPU, 1MB physical reads/writes/memory).' UNION ALL
429- SELECT ' High volatility means the query'' s performance is unpredictable, even if the average looks acceptable.' ;
429+ SELECT ' High volatility means the query'' s performance is unpredictable, even if the average looks acceptable.' UNION ALL
430+ SELECT REPLICATE (' -' , 100 ) UNION ALL
431+ SELECT ' WORKLOAD CONCENTRATION SUMMARY (separate result set, returned before the query details):' UNION ALL
432+ SELECT ' total_query_hashes: how many distinct query_hashes had executions in the time window' UNION ALL
433+ SELECT ' surfaced_query_hashes: how many made it into the detail result set after top-N and scoring filters' UNION ALL
434+ SELECT ' top_n_cpu_pct, top_n_duration_pct, top_n_reads_pct, top_n_writes_pct, top_n_memory_pct, top_n_executions_pct:' UNION ALL
435+ SELECT ' what percentage of the server'' s total for each metric the surfaced queries account for.' UNION ALL
436+ SELECT ' If top_n_cpu_pct = 88.2, the surfaced queries are 88.2% of all CPU in the time window.' UNION ALL
437+ SELECT ' workload_profile: Concentrated (>= 50%), Moderate (25-49%), or Flat (< 25%).' UNION ALL
438+ SELECT ' Based on the highest concentration across all six metrics.' UNION ALL
439+ SELECT ' Concentrated: a few queries dominate. Tuning them individually will have the most impact.' UNION ALL
440+ SELECT ' Moderate: some outliers, but a long tail of smaller queries also matters.' UNION ALL
441+ SELECT ' Flat: no dominant queries. Individual query tuning has limited value.' UNION ALL
442+ SELECT ' recommendation: actionable guidance based on the workload profile.' UNION ALL
443+ SELECT ' For flat workloads: consider forced parameterization, look for missing schema prefixes,' UNION ALL
444+ SELECT ' temp table patterns causing recompilation, or RECOMPILE hints generating unique plans.' ;
430445
431446 /*
432447 Limitations
@@ -4952,6 +4967,180 @@ OPTION(RECOMPILE);' + @nc10;
49524967 )
49534968 FROM #hi_interesting AS i;
49544969
4970+ /* Step 5c: Workload concentration summary*/
4971+ DECLARE
4972+ @hi_max_pct decimal (5 , 1 );
4973+
4974+ SELECT
4975+ @hi_max_pct =
4976+ MAX (v .pct )
4977+ FROM
4978+ (
4979+ SELECT
4980+ pct = SUM (CONVERT (decimal (5 , 1 ), s .cpu_share ))
4981+ FROM #hi_scored AS s
4982+ JOIN #hi_interesting AS i
4983+ ON s .query_hash = i .query_hash
4984+
4985+ UNION ALL
4986+
4987+ SELECT
4988+ pct = SUM (CONVERT (decimal (5 , 1 ), s .duration_share ))
4989+ FROM #hi_scored AS s
4990+ JOIN #hi_interesting AS i
4991+ ON s .query_hash = i .query_hash
4992+
4993+ UNION ALL
4994+
4995+ SELECT
4996+ pct = SUM (CONVERT (decimal (5 , 1 ), s .reads_share ))
4997+ FROM #hi_scored AS s
4998+ JOIN #hi_interesting AS i
4999+ ON s .query_hash = i .query_hash
5000+
5001+ UNION ALL
5002+
5003+ SELECT
5004+ pct = SUM (CONVERT (decimal (5 , 1 ), s .writes_share ))
5005+ FROM #hi_scored AS s
5006+ JOIN #hi_interesting AS i
5007+ ON s .query_hash = i .query_hash
5008+
5009+ UNION ALL
5010+
5011+ SELECT
5012+ pct = SUM (CONVERT (decimal (5 , 1 ), s .memory_share ))
5013+ FROM #hi_scored AS s
5014+ JOIN #hi_interesting AS i
5015+ ON s .query_hash = i .query_hash
5016+
5017+ UNION ALL
5018+
5019+ SELECT
5020+ pct = SUM (CONVERT (float , s .executions_share ))
5021+ FROM #hi_scored AS s
5022+ JOIN #hi_interesting AS i
5023+ ON s .query_hash = i .query_hash
5024+ ) AS v (pct);
5025+
5026+ SELECT
5027+ total_query_hashes =
5028+ (SELECT COUNT_BIG (* ) FROM #hi_query_stats),
5029+ surfaced_query_hashes =
5030+ (SELECT COUNT_BIG (* ) FROM #hi_interesting),
5031+ top_n_cpu_pct =
5032+ CONVERT
5033+ (
5034+ decimal (5 , 1 ),
5035+ ISNULL
5036+ (
5037+ (
5038+ SELECT
5039+ SUM (CONVERT (decimal (5 , 1 ), s .cpu_share ))
5040+ FROM #hi_scored AS s
5041+ JOIN #hi_interesting AS i
5042+ ON s .query_hash = i .query_hash
5043+ ),
5044+ 0
5045+ )
5046+ ),
5047+ top_n_duration_pct =
5048+ CONVERT
5049+ (
5050+ decimal (5 , 1 ),
5051+ ISNULL
5052+ (
5053+ (
5054+ SELECT
5055+ SUM (CONVERT (decimal (5 , 1 ), s .duration_share ))
5056+ FROM #hi_scored AS s
5057+ JOIN #hi_interesting AS i
5058+ ON s .query_hash = i .query_hash
5059+ ),
5060+ 0
5061+ )
5062+ ),
5063+ top_n_reads_pct =
5064+ CONVERT
5065+ (
5066+ decimal (5 , 1 ),
5067+ ISNULL
5068+ (
5069+ (
5070+ SELECT
5071+ SUM (CONVERT (decimal (5 , 1 ), s .reads_share ))
5072+ FROM #hi_scored AS s
5073+ JOIN #hi_interesting AS i
5074+ ON s .query_hash = i .query_hash
5075+ ),
5076+ 0
5077+ )
5078+ ),
5079+ top_n_writes_pct =
5080+ CONVERT
5081+ (
5082+ decimal (5 , 1 ),
5083+ ISNULL
5084+ (
5085+ (
5086+ SELECT
5087+ SUM (CONVERT (decimal (5 , 1 ), s .writes_share ))
5088+ FROM #hi_scored AS s
5089+ JOIN #hi_interesting AS i
5090+ ON s .query_hash = i .query_hash
5091+ ),
5092+ 0
5093+ )
5094+ ),
5095+ top_n_memory_pct =
5096+ CONVERT
5097+ (
5098+ decimal (5 , 1 ),
5099+ ISNULL
5100+ (
5101+ (
5102+ SELECT
5103+ SUM (CONVERT (decimal (5 , 1 ), s .memory_share ))
5104+ FROM #hi_scored AS s
5105+ JOIN #hi_interesting AS i
5106+ ON s .query_hash = i .query_hash
5107+ ),
5108+ 0
5109+ )
5110+ ),
5111+ top_n_executions_pct =
5112+ CONVERT
5113+ (
5114+ decimal (5 , 1 ),
5115+ ISNULL
5116+ (
5117+ (
5118+ SELECT
5119+ SUM (CONVERT (float , s .executions_share ))
5120+ FROM #hi_scored AS s
5121+ JOIN #hi_interesting AS i
5122+ ON s .query_hash = i .query_hash
5123+ ),
5124+ 0
5125+ )
5126+ ),
5127+ workload_profile =
5128+ CASE
5129+ WHEN @hi_max_pct >= 50
5130+ THEN N ' Concentrated'
5131+ WHEN @hi_max_pct >= 25
5132+ THEN N ' Moderate'
5133+ ELSE N ' Flat'
5134+ END ,
5135+ recommendation =
5136+ CASE
5137+ WHEN @hi_max_pct >= 50
5138+ THEN N ' Tune the surfaced queries for the most impact.'
5139+ WHEN @hi_max_pct >= 25
5140+ THEN N ' Some outliers, but a significant long tail. Tune surfaced queries, then investigate hash sprawl from missing schema prefixes, RECOMPILE hints, or temp table patterns.'
5141+ ELSE N ' No dominant queries. Look for forced parameterization opportunities, missing schema prefixes (dbo.Proc vs Proc), temp table patterns causing recompilation, or RECOMPILE hints generating unique plans.'
5142+ END ;
5143+
49555144 /* Step 6: Final output (dynamic SQL for OUTER APPLY to query plan)*/
49565145 SELECT
49575146 @current_table = ' selecting high impact results' ,
0 commit comments