feat: Add support for LEFT JOIN LATERAL#21352
Open
neilconway wants to merge 2 commits intoapache:mainfrom
Open
feat: Add support for LEFT JOIN LATERAL#21352neilconway wants to merge 2 commits intoapache:mainfrom
LEFT JOIN LATERAL#21352neilconway wants to merge 2 commits intoapache:mainfrom
Conversation
LEFT JOIN LATERAL
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?
Rationale for this change
This PR adds support for LEFT join semantics for lateral joins. This is a bit tricky because of how it interacts with compensation for the "count bug". This might be easiest to illustrate with an example; consider this query (Q1):
The initial decorrelation (Q2) is
Ignoring the user's original
ONclause for now. This initial query is wrong, becauset1rows that don't have a match int2will get all-NULLvalues, not0forcount(*)of an empty set. This is the "count bug", and we compensate for that by checking for rows when__always_trueisNULL, and replacing the agg value with the default for that agg (Q3):Now we just need to handle the user's original
ONclause. We can't add this to the rewrittenONclause in Q1, because we don't want the count-bug compensation to fire. But we also can't just add it to theWHEREclause, because we need left join semantics. So we can instead wrap anotherCASEthat re-checks theONcondition and substitutesNULLfor every right-side column:What changes are included in this PR?
Are these changes tested?
Yes.
Are there any user-facing changes?
Support for a new feature.