Repository navigation
perf: read NOT NULL tuple elements of a multi-column NOT IN as scope keys #26214
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
Open
viirya
wants to merge
3
commits into
apache:main
Choose a base branch
from
viirya:multi-column-not-in-scope-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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.
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.
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.
[P2] Preserve early termination when promoting low-cardinality scope keys
This promotion can substantially increase work when the new scope key has few distinct values. For example, consider materialized tables with these schemas and contents:
Previously, both elements were value keys, so
for_each_unmarked_cross_productstopped once all outer rows were marked UNKNOWN. Withb = ypromoted to a scope key,for_each_scope_matchenumerates every matching pair;retain_unmarkeddiscards already-resolved rows only after the lookup has produced them. Both plans return the same result, but the new path keeps traversing the constant-key bucket.A focused executable harness using the actual traversal/iteration helper bodies with minimal storage shims confirmed 8,192 candidate pairs before versus 67,108,864 afterward, with batch size 8,192 and both paths marking exactly 8,192 rows. These are helper-level work counts, not end-to-end query timings. The scalar early-exit path does not apply because the join still has two keys, and NULL marking runs before the empty full-key-map shortcut.
Could we preserve early termination or prune resolved scope entries before applying this transformation unconditionally, and add a constant/low-cardinality scope benchmark?
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.
Thanks, confirmed. On the example from your comment, the scope-key path takes ~300 ms versus ~1 ms when
b = ystays a value key. With #26213 merged it now plans asRightAntiand regresses the same way, andLeftMarktoo (218 ms vs 1 ms).The root cause is not specific to this PR: the scope-key marking walks every pair in a bucket and drops already-marked rows only afterwards, so a correlated scalar
NOT INwith a low-cardinality equality correlation already hits it on main (a NOT IN (SELECT x FROM inner_t i WHERE i.y = o.b)takes ~300 ms on the same data). #25679 works on this by skipping marked rows in the scope lookup and grouping probe rows by scope hash.Since this PR only makes that path more common, I'll keep it on hold until a fix like #25679 lands, and then add a constant/low-cardinality scope-key query to the
null_aware_joinbenchmark here.