Skip to content

Commit 003103e

Browse files
sp_QuickieStore: add new diagnostics to @find_high_impact
Add parallel efficiency metric using (cpu/elapsed - 1) / (dop - 1) formula to score how effectively queries use parallelism. Also add four new diagnostic rules: - intermittent waits: duration volatile but CPU stable (external waits) - rare but expensive: low execution count but high resource share - adhoc bloat: many query_id variants per query_hash - scan heavy: high physical reads per execution Tested clean on sql2016-sql2025 across PerformanceMonitor, StackOverflow2013, StackOverflow2010, and hammerdb_tpch databases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 804af00 commit 003103e

1 file changed

Lines changed: 116 additions & 3 deletions

File tree

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,8 @@ BEGIN
39563956
total_memory_mb decimal(38, 6) NOT NULL,
39573957
avg_memory_mb decimal(38, 6) NULL,
39583958
min_memory_mb decimal(38, 6) NULL,
3959-
max_memory_mb decimal(38, 6) NULL
3959+
max_memory_mb decimal(38, 6) NULL,
3960+
max_dop bigint NULL
39603961
);
39613962

39623963
CREATE TABLE
@@ -4103,7 +4104,9 @@ SELECT
41034104
min_memory_mb =
41044105
MIN(qsrs.min_query_max_used_memory * 8.0 / 1024.0),
41054106
max_memory_mb =
4106-
MAX(qsrs.max_query_max_used_memory * 8.0 / 1024.0)
4107+
MAX(qsrs.max_query_max_used_memory * 8.0 / 1024.0),
4108+
max_dop =
4109+
MAX(qsrs.max_dop)
41074110
FROM ' + @database_name_quoted + N'.sys.query_store_query AS qsq
41084111
JOIN ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
41094112
ON qsq.query_id = qsp.query_id
@@ -4178,7 +4181,8 @@ OPTION(RECOMPILE);' + @nc10;
41784181
total_memory_mb,
41794182
avg_memory_mb,
41804183
min_memory_mb,
4181-
max_memory_mb
4184+
max_memory_mb,
4185+
max_dop
41824186
)
41834187
EXECUTE sys.sp_executesql
41844188
@sql,
@@ -5104,6 +5108,115 @@ SELECT
51045108
N'' MB/exec)''
51055109
END,
51065110
N''''
5111+
) +
5112+
ISNULL
5113+
(
5114+
N'' | '' +
5115+
CASE
5116+
WHEN s.max_dop > 1
5117+
AND s.avg_duration_ms > 0
5118+
THEN N''parallel efficiency ('' +
5119+
CONVERT
5120+
(
5121+
nvarchar(20),
5122+
CONVERT
5123+
(
5124+
decimal(5, 1),
5125+
IIF
5126+
(
5127+
(CONVERT(float, s.avg_cpu_ms) / s.avg_duration_ms - 1.0) /
5128+
(s.max_dop - 1.0) * 100.0 > 100.0,
5129+
100.0,
5130+
IIF
5131+
(
5132+
(CONVERT(float, s.avg_cpu_ms) / s.avg_duration_ms - 1.0) /
5133+
(s.max_dop - 1.0) * 100.0 < 0.0,
5134+
0.0,
5135+
(CONVERT(float, s.avg_cpu_ms) / s.avg_duration_ms - 1.0) /
5136+
(s.max_dop - 1.0) * 100.0
5137+
)
5138+
)
5139+
)
5140+
) +
5141+
N''% @ DOP '' +
5142+
CONVERT(nvarchar(10), s.max_dop) +
5143+
N'')''
5144+
END,
5145+
N''''
5146+
) +
5147+
ISNULL
5148+
(
5149+
N'' | '' +
5150+
CASE
5151+
WHEN (s.max_duration_ms - s.min_duration_ms) /
5152+
NULLIF(s.avg_duration_ms, 0) > 10
5153+
AND s.max_duration_ms > 1000
5154+
AND (s.max_cpu_ms - s.min_cpu_ms) /
5155+
NULLIF(s.avg_cpu_ms, 0) < 3
5156+
THEN N''intermittent waits (duration '' +
5157+
CONVERT
5158+
(
5159+
nvarchar(20),
5160+
CONVERT(integer, (s.max_duration_ms - s.min_duration_ms) / NULLIF(s.avg_duration_ms, 0))
5161+
) +
5162+
N''x, cpu '' +
5163+
CONVERT
5164+
(
5165+
nvarchar(20),
5166+
CONVERT(decimal(5, 1), (s.max_cpu_ms - s.min_cpu_ms) / NULLIF(s.avg_cpu_ms, 0))
5167+
) +
5168+
N''x)''
5169+
END,
5170+
N''''
5171+
) +
5172+
ISNULL
5173+
(
5174+
N'' | '' +
5175+
CASE
5176+
WHEN s.total_executions < 10
5177+
AND (s.cpu_share > 5
5178+
OR s.duration_share > 5)
5179+
THEN N''rare but expensive ('' +
5180+
CONVERT(nvarchar(20), s.total_executions) +
5181+
N'' execs, '' +
5182+
CONVERT
5183+
(
5184+
nvarchar(20),
5185+
CONVERT
5186+
(
5187+
decimal(5, 1),
5188+
IIF(s.cpu_share > s.duration_share, s.cpu_share, s.duration_share)
5189+
)
5190+
) +
5191+
N''% share)''
5192+
END,
5193+
N''''
5194+
) +
5195+
ISNULL
5196+
(
5197+
N'' | '' +
5198+
CASE
5199+
WHEN s.query_count > 10
5200+
THEN N''adhoc bloat ('' +
5201+
CONVERT(nvarchar(20), s.query_count) +
5202+
N'' variants)''
5203+
END,
5204+
N''''
5205+
) +
5206+
ISNULL
5207+
(
5208+
N'' | '' +
5209+
CASE
5210+
WHEN s.avg_physical_reads_mb > 50
5211+
THEN N''scan heavy ('' +
5212+
CONVERT
5213+
(
5214+
nvarchar(20),
5215+
CONVERT(decimal(10, 1), s.avg_physical_reads_mb)
5216+
) +
5217+
N'' MB/exec)''
5218+
END,
5219+
N''''
51075220
),
51085221
1,
51095222
3,

0 commit comments

Comments
 (0)