[SPARK-36028][SQL] Allow Project to host outer references in scalar subqueries #33235
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.
What changes were proposed in this pull request?
This PR allows the
Projectnode to host outer references in scalar subqueries whendecorrelateInnerQueryis enabled. It is already supported by the new decorrelation framework and theRewriteCorrelatedScalarSubqueryrule.Note currently by default all correlated subqueries will be decorrelated, which is not necessarily the most optimal approach. Consider
SELECT (SELECT c1) FROM t. This should be optimized asSELECT c1 FROM tinstead of rewriting it as a left outer join. This will be done in a separate PR to optimize correlated scalar/lateral subqueries with OneRowRelation.Why are the changes needed?
To allow more types of correlated scalar subqueries.
Does this PR introduce any user-facing change?
Yes. This PR allows outer query column references in the SELECT cluase of a correlated scalar subquery. For example:
Before this change:
After this change:
How was this patch tested?
Added unit tests and SQL tests.