Fix @wait_filter matching waits from all of Query Store history (#852) - #853
Merged
Merged
Conversation
The #wait_filter populate aggregated query_store_wait_stats with no date restriction, so queries whose waits happened entirely outside the requested window still passed the filter, and the TOP was ranked by all-history wait totals. Joining to query_store_runtime_stats on (plan_id, runtime_stats_interval_id, execution_type) and filtering last_execution_time by the date range matches the semantics of the main where clause and the wait sort order joins from #851. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Claude finished @erikdarlingdata's task in 2m 5s —— View job Review complete ✅
SummaryThis is a clean, correct fix. The
Correctness
Style / repo constraints
No blocking issues found. Nice catch on the false-negative in the leading-edge-of-window scenario mentioned in the PR description — good that the repro caught it before landing. |
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.
Fixes #852 — the sibling of #850/#851, found while verifying that fix.
What was wrong
The
#wait_filterpopulate aggregatedsys.query_store_wait_statsperplan_idwith no date or interval restriction at all, then fed the plan_ids into anEXISTSagainst the date-windowed runtime stats. Two consequences:TOP (@top)was ranked by all-history wait totals, so plans with big waits long ago could crowd out plans that actually waited inside the window — wrong in both directions.The fix
Join
query_store_wait_statstoquery_store_runtime_statson(plan_id, runtime_stats_interval_id, execution_type)and filterqsrs.last_execution_timeby@start_date/@end_date— the same join grain as #851 and the same date semantics as the proc's main@where_clause. The block'ssp_executesqlcall previously only passed@top; it now passes the date parameters too.Validation
SQL Server 2022 (RTM-CU26), Query Store with 1-minute intervals, two queries against the same table:
@wait_filter = 'lock'results:Tested
sys.query_store_wait_stats.qsrsi.start_time >= @start_dateand the repro caught it dropping the partial interval at the window's leading edge (false negative for a query that waited inside the window). The final shape filters onqsrs.last_execution_timeinstead, which has no such boundary mismatch and matches the rest of the proc.Not tested
@get_all_databases = 1(no code path difference — same dynamic SQL per database;#wait_filteris truncated per database iteration).query_store_wait_stats(2017+), and CI runs 2017/2019/2022/2025.