Skip to content

Optimize Lite query store collector: CTE + 60min window#137

Merged
erikdarlingdata merged 1 commit intodevfrom
feature/lite-query-store-optimization
Feb 19, 2026
Merged

Optimize Lite query store collector: CTE + 60min window#137
erikdarlingdata merged 1 commit intodevfrom
feature/lite-query-store-optimization

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • Restructure Query Store collection query to use a CTE for aggregation/ranking, deferring the expensive sys.query_store_query_text join until after TOP 100 filtering
  • Eliminates nvarchar(max) column from GROUP BY, reducing sort memory and I/O
  • Narrows lookback window from 24 hours to 60 minutes to match collection interval

Details

The original query joined query_store_query_text (which contains nvarchar(max) query text) before grouping, forcing SQL Server to sort massive text values. The CTE approach:

  1. Aggregates and ranks in the CTE using only integer/decimal columns
  2. Applies TOP 100 filter
  3. Joins query text only for the final 100 rows

Test plan

  • dotnet build -c Debug — zero warnings
  • Launch Lite, connect to a server with Query Store enabled
  • Verify Query Store tab populates correctly
  • Confirm collection timing in status bar is faster than before

Addresses #134.

🤖 Generated with Claude Code

Restructure the Query Store collection query to avoid nvarchar(max)
query_sql_text in GROUP BY. Aggregation and ranking now happen in a
CTE that only touches sys.query_store_query, query_store_plan, and
query_store_runtime_stats. The expensive join to
sys.query_store_query_text is deferred until after TOP 100 filtering,
dramatically reducing sort memory and I/O.

Also narrows the lookback window from 24 hours to 60 minutes to match
the collection interval and reduce scan volume.

Addresses #134.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit daef70e into dev Feb 19, 2026
3 checks passed
@erikdarlingdata erikdarlingdata deleted the feature/lite-query-store-optimization branch February 20, 2026 13:20
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