Skip to content

sp_QuickieStore: rewrite representative text query to avoid grouping on nvarchar(max)#701

Merged
erikdarlingdata merged 3 commits intodevfrom
feature/hi-text-rewrite
Mar 23, 2026
Merged

sp_QuickieStore: rewrite representative text query to avoid grouping on nvarchar(max)#701
erikdarlingdata merged 3 commits intodevfrom
feature/hi-text-rewrite

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

The #hi_representative_text query in @find_high_impact grouped by query_hash + query_sql_text, forcing the Hash Aggregate to hash nvarchar(max) values — slow and memory-hungry.

Rewritten to:

  1. Group by query_hash + query_text_id (both fixed-width) in a subquery
  2. Pick the rn = 1 winner
  3. Join back to query_store_query_text only for that single row per hash

Test plan

  • SQL2022 — same results, clean execution
  • SQL2016 — same results, clean execution

🤖 Generated with Claude Code

erikdarlingdata and others added 3 commits March 23, 2026 15:02
sp_QuickieStore: @find_high_impact output fixes
…on nvarchar(max)

The #hi_representative_text query grouped by query_hash + query_sql_text,
forcing the Hash Aggregate to hash nvarchar(max) values. Rewritten to
group by query_hash + query_text_id (both fixed-width) in a subquery,
then join back to query_store_query_text only for the rn=1 winner.

Tested on SQL2022 and SQL2016.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 2b2143c into dev Mar 23, 2026
5 checks passed
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