sp_QuickieStore: fix plan_count/query_count under-count in @find_high_impact#793
Merged
Merged
Conversation
…_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>
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the
@find_high_impactcode path, theplan_countandquery_countcolumns were sourced from#hi_query_stats, which only aggregates plans and queries that were active within the analyzed time window. The adjacentplan_id_listandquery_id_listcolumns are built from the unfiltered#hi_id_staging_*tables (all-time).Result: any
query_hashwith retired plans showed aplan_countlower than the number of IDs actually listed inplan_id_list(and likewise forquery_count). The help text documents both columns as all-time totals ("across all variants" / "share this hash").Fix
Source the displayed
plan_countandquery_countfrom#hi_id_staging_plansand#hi_id_staging_queriesso they match their_id_listcounterparts. The window-scoped#hi_query_stats.plan_countis 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:
0x11ACF1DF8D17C1F60xF1C03AF2954FFC950xDD142572DE1019CBplan_countandquery_countnow exactly equal the number of IDs in their respective_id_listcolumns.🤖 Generated with Claude Code