Repository navigation
query_store: force HASH JOIN on the plan and text fetch statements #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
14cc97d
query_store: force HASH JOIN on the plan and text fetch statements
erikdarlingdata c8ffaaa
CHANGELOG: move the HASH JOIN entry from Added to Fixed
erikdarlingdata 8a5188a
Correct the seek->scan note: the scan does happen, and it is cheap
erikdarlingdata 3ea41f5
Record the memory-grant trade the HASH JOIN hint makes
erikdarlingdata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit / worth a sentence in the comment above rather than a blocker:
OPTION(RECOMPILE, HASH JOIN)forces a Hash Match, which (unlike the Nested Loops it replaces) requires a workspace memory grant. That's clearly the right trade on the OMEGA case this PR fixes (60s CPU → 0.5s), but this collector can run once per database per cycle across a fleet of concurrently-collected databases. On an instance already under memory pressure, an unconditional hash-join grant on every invocation — even ones with only a handful of candidate ids where Nested Loops would've been cheap and grant-free — is a small but real behavior change versus letting the optimizer choose per-statement. Given how carefully everything else here is measured, it'd be worth either a one-line note confirming this was considered (e.g. observed grant size on OMEGA), or confirming it's a non-issue given typical candidate-set sizes. Same applies to the text fetch at line 1417.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, and you are right on the mechanism — I had not measured it. Now I have, and the answer is "real but bounded". Recorded in the comment on both builders in 3ea41f5.
Grants on a 40,882-plan Query Store, no spill in any case:
Three things fall out of that:
MaxCandidatePlanscaps the input at 512, which caps the grant at ~3.6 MB — of which the optimizer was already paying 1,760 KB on its own, because at that size it picks a hash anyway. So at the large end the hint roughly doubles an existing grant rather than introducing one.On fleet concurrency: sweeps are concurrent across servers but the per-item loop is sequential within a server on one connection, so the worst case is a few concurrent sweeps' worth — single-digit MB, against a statement that was burning 55,000–61,000 ms of CPU per invocation.
I also named the symptom in the comment for the case where this is wrong somewhere I have not measured:
RESOURCE_SEMAPHOREwaits or a hash spill on the monitored instance. Neither appears in anything measured here.Applied to the text fetch as well, as you asked.