Skip to content

Commit cc35de9

Browse files
sp_QuickieStore: tighten plan instability diagnostic in @find_high_impact
Previously any query with >1 plan was flagged, which produced false positives on stable workloads with many executions. Now requires fewer than 5 executions per plan (frequent recompilation) and excludes queries with RECOMPILE hints where multiple plans are expected. Tested on SQL2022 against PerformanceMonitor and hammerdb_tpcc. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7108a96 commit cc35de9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ BEGIN
419419
SELECT ' (blocking, resource contention, I/O). The multiplier shows how much worse duration is vs CPU.' UNION ALL
420420
SELECT ' param sensitive (1 plan, cpu Nx) - single plan but wildly varying CPU times across executions.' UNION ALL
421421
SELECT ' Classic parameter sniffing: one plan shape that works for some parameter values but not others.' UNION ALL
422-
SELECT ' plan instability (N plans) - multiple plans compiled for variants of this query.' UNION ALL
423-
SELECT ' The optimizer keeps choosing different strategies, which usually means inconsistent performance.' UNION ALL
422+
SELECT ' plan instability (N plans) - multiple plans with fewer than 5 executions per plan, excluding RECOMPILE hints.' UNION ALL
423+
SELECT ' The optimizer keeps recompiling frequently, which usually means inconsistent performance.' UNION ALL
424424
SELECT ' spills/spools (N MB/exec) - writes detected on a SELECT-like query (no INSERT/UPDATE/DELETE/MERGE).' UNION ALL
425425
SELECT ' This typically means tempdb spills from underestimated memory grants, or worktable spools.' UNION ALL
426426
SELECT REPLICATE('-', 100) UNION ALL
@@ -5250,6 +5250,8 @@ SELECT
52505250
N'' | '' +
52515251
CASE
52525252
WHEN s.plan_count > 1
5253+
AND s.total_executions / s.plan_count < 5
5254+
AND rt.query_sql_text NOT LIKE N''%RECOMPILE%''
52535255
THEN N''plan instability ('' +
52545256
CONVERT(nvarchar(10), s.plan_count) +
52555257
N'' plans)''

0 commit comments

Comments
 (0)