Improve Query Store grid query performance (#143)#144
Merged
erikdarlingdata merged 1 commit intodevfrom Mar 25, 2026
Merged
Conversation
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>
This was referenced Mar 25, 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.
Summary
Community-reported performance fix — 41s → 3s on slow machines / cloud instances.
Three changes based on issue #143 by @rferraton:
Remove
WHERE p.query_plan IS NOT NULLfrom the ranked CTE — predicate onnvarchar(max)causes an expensive implicit conversion scan. NULL plans are already handled by the C# reader (row is skipped).Two-phase temp table approach — materialize TOP N into
#top_plansusing only numeric columns, then join toquery_text/plan XMLtables for just the winners. Avoids dragging expensivenvarchar(max)columns through the entire CTE.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 whereq.*/p.*are available.Test plan
🤖 Generated with Claude Code