Skip to content

Improve Query Store grid query performance (#143)#144

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/143-query-store-perf
Mar 25, 2026
Merged

Improve Query Store grid query performance (#143)#144
erikdarlingdata merged 1 commit intodevfrom
fix/143-query-store-perf

Conversation

@erikdarlingdata
Copy link
Owner

Summary

Community-reported performance fix — 41s → 3s on slow machines / cloud instances.

Three changes based on issue #143 by @rferraton:

  1. Remove WHERE p.query_plan IS NOT NULL from the ranked CTE — predicate on nvarchar(max) causes an expensive implicit conversion scan. NULL plans are already handled by the C# reader (row is skipped).

  2. Two-phase temp table approach — materialize TOP N into #top_plans using only numeric columns, then join to query_text/plan XML tables for just the winners. Avoids dragging expensive nvarchar(max) columns through the entire CTE.

  3. Remove OPTION (LOOP JOIN) — reported 3x faster without it across multiple environments.

Filter clauses (query_id, query_hash, plan_hash, module_name) remain in the final SELECT where q.*/p.* are available.

Test plan

  • Build succeeds (0 errors)
  • Tested two-phase SQL batch on SQL2022 — correct results
  • Verify grid loads correctly in app with the new query
  • Community tester confirms improvement on slow machines

🤖 Generated with Claude Code

Three changes from community feedback (41s → 3s on slow machines):

1. Remove WHERE p.query_plan IS NOT NULL from the ranked CTE — this
   predicate on nvarchar(max) causes an expensive implicit conversion
   scan. NULL plans are already handled by the C# reader (skip row).

2. Two-phase approach: materialize TOP N into #top_plans first using
   only numeric columns, then join to query_text/plan XML tables for
   just the winners. Avoids dragging expensive nvarchar(max) columns
   through the entire CTE evaluation.

3. Remove OPTION (LOOP JOIN) — reported 3x faster without it on
   multiple test environments.

Tested on SQL2022 with PerformanceMonitor Query Store data.

Closes #143

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 8529af3 into dev Mar 25, 2026
2 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/143-query-store-perf branch March 25, 2026 13:21
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