Enhance join reordering to work with non-simple equi-join clauses#21153
Enhance join reordering to work with non-simple equi-join clauses#21153tdcmeehan merged 1 commit intoprestodb:masterfrom
Conversation
1c78aa8 to
f000340
Compare
There was a problem hiding this comment.
is this unrelated?
There was a problem hiding this comment.
Yes. I noticed that the cherry-picked code had this added to ensure that we always run this test with no join ordering. This was missed when we pulled it into Presto.
|
Can you highlight the change you added compared with previous PR (maybe by adding PR comments for the code) to help review? |
There was a problem hiding this comment.
@feilong-liu Here are the delta of the changes from the previous PR
There was a problem hiding this comment.
The core of the changes from the previous PR are to this class
There was a problem hiding this comment.
We recursively resolve all intermediate assignments to only use the input variables of the join sources, e.g:
inter_3 = inter_2
inter_2 = inter_1 + join_op_1
inter_1 = join_op_2 + join_op_0
is rewritten to :
inter_3 = join_op_2 + join_op_0 + join_op_1
inter_2 = join_op_2 + join_op_0 + join_op_1
inter_1 = join_op_2 + join_op_0
There was a problem hiding this comment.
While building the MultiJoinNode, we take care to set the output variables of the MultiJoinNode to only refer to the input variables.
Any output variables that were using variables from the intermediate project nodes are tracked in overallAssigments
More details are in code comments
There was a problem hiding this comment.
I modified the test to demonstrate how multiple nested Project's are flattened
There was a problem hiding this comment.
renamePlusSum is a variable from an intermediate Project - this gets set on the overall assignment of the MultiJoinNode with the resolved variables of the input sources
presto-expressions/src/main/java/com/facebook/presto/expressions/LogicalRowExpressions.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ReorderJoins.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ReorderJoins.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ReorderJoins.java
Outdated
Show resolved
Hide resolved
f000340 to
cbef94e
Compare
Join predicates like `left.key = right1.key1 + right2.key2` can reduce the join space by appearing as Project nodes or Join noes with no equi-join clauses in the join graph. This commit fixes this behavior by removing any intermediate Projects in the join graph and only creating them on-the-fly while choosing the join order
cbef94e to
06dbf27
Compare
Description
Enhance join-reordering to work with non-simple equi-join predicates
Motivation and Context
Reapplies #20413 with fixes to bugs identified -
Additionally, the feature config for
optimizer.handle-complex-equi-joinswas changed to a defaultfalseto allow testing this in isolation/rollout. We will set this to defaulttruein the future, once we test with more workloadsTest Plan
New tests added to address the bug identified -
testProjectNodesBetweenJoinNodesAreFlattenedForComplexEquiJoinswas rewritten to include multiple ProjectNode's (including nested Projects and a simple rename projection). Additionally, further assertions were added on the overall assignments built and the output variables that were rewrittentestComplexEquiJoinCriteriaForJoinsWithUSINGClausewas added which runs aSELECT *query with aUSINGclauseContributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.