Skip to content

sp_QuickieStore: split Step 1 aggregate to avoid 4-way DMV join#715

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/hi-split-step1-aggregate
Mar 24, 2026
Merged

sp_QuickieStore: split Step 1 aggregate to avoid 4-way DMV join#715
erikdarlingdata merged 1 commit intodevfrom
fix/hi-split-step1-aggregate

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

Split the initial 4-way DMV join (qsq → qsp → qsrs → qsrsi) into two stages:

  • Step 1a: Aggregate runtime_stats by plan_id (2 DMVs: qsrs + qsrsi)
  • Step 1b: Roll up to query_hash from pre-aggregated temp table (2 DMVs: qsp + qsq)

Follows the pattern used elsewhere in sp_QuickieStore where Query Store views are touched individually or in small groups.

Test plan

  • SQL2022 — same results (96 hashes, 32 surfaced)
  • SQL2016 — same results

🤖 Generated with Claude Code

The initial aggregate query joined all 4 Query Store DMVs together
(qsq → qsp → qsrs → qsrsi), causing the optimizer to pick bad plans
with TVFs taking 8+ seconds.

Split into two stages following the pattern used elsewhere in the proc:
- Step 1a: qsrs + qsrsi → #hi_plan_stats (aggregate to plan_id level)
- Step 1b: #hi_plan_stats + qsp + qsq → #hi_query_stats (roll up to
  query_hash, driving from a small pre-aggregated temp table)

Tested on SQL2022 (StackOverflow2013) and SQL2016 (StackOverflow2010).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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