Repository navigation
Conversation
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.
Which issue does this PR close?
Closes #27764.
Rationale for this change
A correlated range predicate can match several different inner keys for one outer row. For example, when the outer key is 1, both 2 and 3 contribute to
COUNT(*). EvaluatingHAVINGseparately for each inner key would change that count. The existing optimizer leaves this subquery correlated, and physical planning fails.What changes are included in this PR?
Add a fallback for correlated
EXISTSover an ungrouped aggregate withHAVING. It materializes the outer input once, joins each distinct tuple of outer correlation values to its matching inner rows, and evaluates the aggregate andHAVINGper tuple. A marker excludes the synthetic row from an unmatched left join, soCOUNT(*)still sees zero input rows. A null-safe join maps the passing tuples back to the original outer rows, preserving duplicates.The fallback skips volatile expressions and nested subqueries. Its cost depends on the number of distinct outer tuples and the number of matching inner rows.
What is the testing strategy for this PR?
Six SQL regression cases in
subquery_decorrelation.sltcover the reportedEXISTSandNOT EXISTSqueries, duplicate outer rows, NULL keys, empty aggregate input, and an aggregate filter with two correlated bounds. Local formatting, all-target/all-feature Clippy, and the extended workspace test suite passed.Are there any user-facing changes?
Yes. The example in #27764 now returns 1 and 2 for
EXISTSand 3 forNOT EXISTS.