This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d58498841a [fix](Nereids) Should copy JoinReorderContext for
PushdownProject (#19508)
d58498841a is described below
commit d58498841a963b6bafa16706cb9b347bdb9429b5
Author: jakevin <[email protected]>
AuthorDate: Thu May 11 21:05:12 2023 +0800
[fix](Nereids) Should copy JoinReorderContext for PushdownProject (#19508)
1. should copy JoinReorderContext
2. verify bushy tree join reorder
---
.../exploration/join/JoinExchangeRightProject.java | 2 +-
.../join/PushdownProjectThroughInnerJoin.java | 4 +-
.../join/PushdownProjectThroughSemiJoin.java | 2 +-
.../nereids/sqltest/CascadesJoinReorderTest.java | 112 ++++++++++++++++++---
4 files changed, 102 insertions(+), 18 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
index 6403c48efe..d1d54e1dc1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
@@ -101,7 +101,7 @@ public class JoinExchangeRightProject extends
OneExplorationRuleFactory {
newTopJoinHashJoinConjuncts,
newTopJoinOtherJoinConjuncts, JoinHint.NONE,
left, right);
JoinExchange.setNewLeftJoinReorder(newLeftJoin, leftJoin);
- JoinExchange.setNewRightJoinReorder(newRightJoin,
leftJoin);
+ JoinExchange.setNewRightJoinReorder(newRightJoin,
rightJoin);
JoinExchange.setNewTopJoinReorder(newTopJoin, topJoin);
return CBOUtils.projectOrSelf(new
ArrayList<>(topJoin.getOutput()), newTopJoin);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
index db243da5fd..a425c27c31 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
@@ -121,7 +121,7 @@ public class PushdownProjectThroughInnerJoin implements
ExplorationRuleFactory {
Plan newLeft = CBOUtils.projectOrSelf(newAProject.build(),
join.left());
if (!rightContains) {
- Plan newJoin = join.withChildrenNoContext(newLeft, join.right());
+ Plan newJoin = join.withChildren(newLeft, join.right());
return CBOUtils.projectOrSelf(new
ArrayList<>(project.getOutput()), newJoin);
}
@@ -132,7 +132,7 @@ public class PushdownProjectThroughInnerJoin implements
ExplorationRuleFactory {
bConditionSlots.stream().filter(slot ->
!bProjectSlots.contains(slot)).forEach(newBProject::add);
Plan newRight = CBOUtils.projectOrSelf(newBProject.build(),
join.right());
- Plan newJoin = join.withChildrenNoContext(newLeft, newRight);
+ Plan newJoin = join.withChildren(newLeft, newRight);
return CBOUtils.projectOrSelf(new ArrayList<>(project.getOutput()),
newJoin);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
index 851c63dc2d..aa814a03e0 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
@@ -89,7 +89,7 @@ public class PushdownProjectThroughSemiJoin implements
ExplorationRuleFactory {
.forEach(newProject::add);
Plan newLeft = CBOUtils.projectOrSelf(newProject, join.left());
- Plan newJoin = join.withChildrenNoContext(newLeft, join.right());
+ Plan newJoin = join.withChildren(newLeft, join.right());
return CBOUtils.projectOrSelf(new ArrayList<>(project.getOutput()),
newJoin);
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/CascadesJoinReorderTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/CascadesJoinReorderTest.java
index b7c575040c..fa919c3b19 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/CascadesJoinReorderTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/sqltest/CascadesJoinReorderTest.java
@@ -17,8 +17,7 @@
package org.apache.doris.nereids.sqltest;
-import org.apache.doris.nereids.rules.exploration.join.InnerJoinLAsscom;
-import org.apache.doris.nereids.rules.exploration.join.JoinCommute;
+import org.apache.doris.nereids.rules.RuleSet;
import org.apache.doris.nereids.util.PlanChecker;
import org.junit.jupiter.api.Assertions;
@@ -46,16 +45,17 @@ public class CascadesJoinReorderTest extends SqlTestBase {
int plansNumber = PlanChecker.from(connectContext)
.analyze(sql)
.rewrite()
- .applyExploration(JoinCommute.ZIG_ZAG.build())
- .applyExploration(InnerJoinLAsscom.INSTANCE.build())
- .applyExploration(JoinCommute.ZIG_ZAG.build())
+ .applyExploration(RuleSet.ZIG_ZAG_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.ZIG_ZAG_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.ZIG_ZAG_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.ZIG_ZAG_TREE_JOIN_REORDER)
.plansNumber();
Assertions.assertEquals(8, plansNumber);
}
@Test
- void testStarFourJoin() {
+ void testStarFourJoinZigzag() {
// Four join
// (n-1)! * 2^(n-1) = 48
String sql = "SELECT * FROM T1 "
@@ -66,16 +66,100 @@ public class CascadesJoinReorderTest extends SqlTestBase {
int plansNumber = PlanChecker.from(connectContext)
.analyze(sql)
.rewrite()
- .applyExploration(JoinCommute.ZIG_ZAG.build())
- .applyExploration(InnerJoinLAsscom.INSTANCE.build())
- .applyExploration(JoinCommute.ZIG_ZAG.build())
- .applyExploration(InnerJoinLAsscom.INSTANCE.build())
- .applyExploration(JoinCommute.ZIG_ZAG.build())
- .applyExploration(InnerJoinLAsscom.INSTANCE.build())
- .applyExploration(JoinCommute.ZIG_ZAG.build())
- .applyExploration(InnerJoinLAsscom.INSTANCE.build())
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
.plansNumber();
Assertions.assertEquals(48, plansNumber);
}
+
+ @Test
+ void testStarFourJoinBushy() {
+ // Four join
+ // (n-1)! * 2^(n-1) = 48
+ String sql = "SELECT * FROM T1 "
+ + "JOIN T2 ON T1.id = T2.id "
+ + "JOIN T3 ON T1.id = T3.id "
+ + "JOIN T4 ON T1.id = T4.id ";
+
+ int plansNumber = PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .plansNumber();
+
+ Assertions.assertEquals(48, plansNumber);
+ }
+
+ @Test
+ void testChainFourJoinBushy() {
+ // Four join
+ // 2^(n-1) * C(n-1) = 40
+ String sql = "SELECT * FROM T1 "
+ + "JOIN T2 ON T1.id = T2.id "
+ + "JOIN T3 ON T2.id = T3.id "
+ + "JOIN T4 ON T3.id = T4.id ";
+
+ int plansNumber = PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .plansNumber();
+
+ Assertions.assertEquals(40, plansNumber);
+ }
+
+ @Test
+ void testChainFiveJoinBushy() {
+ // Five join
+ // 2^(n-1) * C(n-1) = 224
+ String sql = "SELECT * FROM T1 "
+ + "JOIN T2 ON T1.id = T2.id "
+ + "JOIN T3 ON T2.id = T3.id "
+ + "JOIN T4 ON T3.id = T4.id "
+ + "JOIN T1 T5 ON T4.ID = T5.ID";
+
+ int plansNumber = PlanChecker.from(connectContext)
+ .analyze(sql)
+ .rewrite()
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .applyExploration(RuleSet.BUSHY_TREE_JOIN_REORDER)
+ .plansNumber();
+
+ Assertions.assertEquals(224, plansNumber);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]