Fix #286: Query Store query_id filter excludes target before applying#287
Merged
erikdarlingdata merged 1 commit intodevfrom Apr 26, 2026
Merged
Fix #286: Query Store query_id filter excludes target before applying#287erikdarlingdata merged 1 commit intodevfrom
erikdarlingdata merged 1 commit intodevfrom
Conversation
FetchTopPlansAsync applied user filters (--query-id, --plan-id, --query-hash, --query-plan-hash, --module) only in Phase 4, AFTER Phase 3 had already selected TOP N plans by CPU across the entire database. If the user's target query wasn't in the top N by CPU during the time window, it was cut from #top_plans before the filter ever ran — even though Query Store / SSMS / sp_QuickieStore could see it fine. Move the filter into Phase 3's CTE so TOP N is selected from the filtered universe. Conditionally JOIN sys.query_store_query when the filter touches query_hash or object_id (otherwise the join is skipped to avoid penalty in the unfiltered path). Phase 4 filter clause is now redundant and removed. The hash-tree and module-tree methods (FetchByQueryHashTree, FetchByPlanHashTree) already applied filters pre-TOP-N — they're unaffected. Closes #286. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 26, 2026
Merged
erikdarlingdata
added a commit
that referenced
this pull request
Apr 27, 2026
Highlights since v1.8.0: - Minimap for plan navigation (#276) - Colored links by accuracy ratio divergence (#289) - Distinct parallelism subtype icons (#285, #288) - Query Store filter ordering fix (#287) - xunit v2 -> v3 migration (#278) - SqlClient 6 -> 7, ScriptDom 170 -> 180 (#279) - System.CommandLine GA (#280) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #286.
Root cause
FetchTopPlansAsyncapplies user filters (--query-id,--plan-id,--query-hash,--query-plan-hash,--module) only in Phase 4, AFTER Phase 3 has already selected TOP N plans by CPU across the entire database. When the user's target query isn't in the top N by CPU for the window, it gets cut from#top_plansbefore the filter runs — and the result set comes back empty even though Query Store / SSMS /sp_QuickieStorecan see the query fine.Fix
Push the filter into Phase 3's CTE so TOP N is selected from the filtered universe. Conditionally JOIN
sys.query_store_queryonly when the filter touchesquery_hashorobject_id— the unfiltered code path is unchanged and pays no extra cost.The hash-tree and module-tree fetch methods already applied filters pre-TOP-N correctly; they were not touched.
Test plan
--query-idfinds it🤖 Generated with Claude Code