Skip to content

sp_QuickieStore: fix plan_count/query_count under-count in @find_high_impact#793

Merged
erikdarlingdata merged 1 commit into
devfrom
fix/quickiestore-high-impact-plan-count
May 21, 2026
Merged

sp_QuickieStore: fix plan_count/query_count under-count in @find_high_impact#793
erikdarlingdata merged 1 commit into
devfrom
fix/quickiestore-high-impact-plan-count

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Problem

In the @find_high_impact code path, the plan_count and query_count columns were sourced from #hi_query_stats, which only aggregates plans and queries that were active within the analyzed time window. The adjacent plan_id_list and query_id_list columns are built from the unfiltered #hi_id_staging_* tables (all-time).

Result: any query_hash with retired plans showed a plan_count lower than the number of IDs actually listed in plan_id_list (and likewise for query_count). The help text documents both columns as all-time totals ("across all variants" / "share this hash").

Fix

Source the displayed plan_count and query_count from #hi_id_staging_plans and #hi_id_staging_queries so they match their _id_list counterparts. The window-scoped #hi_query_stats.plan_count is retained for the in-window plan instability diagnostics, which intentionally describe churn within the window.

Test plan

Verified on SQL Server 2025 against StackOverflow2013, which has query_hashes with retired plans:

query_hash plan_count (after fix) plan_id_list entries plan_count before fix
0x11ACF1DF8D17C1F6 9 9 7
0xF1C03AF2954FFC95 3 3 2
0xDD142572DE1019CB 4 4 3

plan_count and query_count now exactly equal the number of IDs in their respective _id_list columns.

🤖 Generated with Claude Code

…_impact

In the @find_high_impact code path, plan_count and query_count were
sourced from #hi_query_stats, which only aggregates plans and queries
active within the analyzed time window. The adjacent plan_id_list and
query_id_list columns are built from the unfiltered #hi_id_staging_*
tables (all-time), so any query_hash with retired plans showed a
plan_count lower than the number of IDs listed.

The help text documents both columns as all-time totals ("across all
variants" / "share this hash"). Source the displayed plan_count and
query_count from #hi_id_staging_plans and #hi_id_staging_queries so
they match their _id_list counterparts. The window-scoped
#hi_query_stats.plan_count is retained for the in-window plan
instability diagnostics.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 1087544 into dev May 21, 2026
1 check passed
@erikdarlingdata erikdarlingdata deleted the fix/quickiestore-high-impact-plan-count branch May 21, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant