SQL Subquery Decorrelation - #38929
Closed
damccorm wants to merge 3 commits into
Closed
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #38929 +/- ##
============================================
- Coverage 57.77% 54.32% -3.46%
+ Complexity 12969 1707 -11262
============================================
Files 2509 1062 -1447
Lines 260525 166535 -93990
Branches 10658 1252 -9406
============================================
- Hits 150516 90462 -60054
+ Misses 104318 73860 -30458
+ Partials 5691 2213 -3478
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Adds a custom subquery decorrelation pass to Beam SQL to handle complex correlated subqueries.
The Problem
Calcite's default
SqlToRelConverterdecorrelates most queries, but some complex correlated shapes (like correlatedEXISTSorINsubqueries insidePROJECTorJOINconditions) survive asRexSubQueryor residualLogicalCorrelatenodes.Beam's Volcano planner ruleset has no physical converter rules for a general
LogicalCorrelatenode. When these residues survive, the planner fails with aCannotPlanException.The Fix
Implemented a pre-Volcano normalization pass in
CalciteQueryPlanner.convertToBeamRel:HepPlannerwith Calcite's*SUB_QUERY_TO_CORRELATErules to turn any un-expandedRexSubQueryinto aLogicalCorrelate.RelDecorrelator.decorrelateQueryto lower these correlates into standard relational shapes (Join,Aggregate,Project,Filter) which existing Beam rules already know how to handle.RelOptUtil.getVariablesUsed), making it a no-op for shapes likeUNNEST(LogicalCorrelate(_, Uncollect)) which define but do not reference a correlation variable, preserving them forBeamUnnestRule.Added a detailed design document in
decorrelation_design.mdexplaining the approach and the Volcano planner convergence safety.