You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ja...@apache.org on 2022/12/01 02:49:50 UTC
[doris] branch master updated: [enhancement](Nereids) avoid add project that output same with child to memo (#14180)
This is an automated email from the ASF dual-hosted git repository.
jakevin 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 3c6b96b9be [enhancement](Nereids) avoid add project that output same with child to memo (#14180)
3c6b96b9be is described below
commit 3c6b96b9be3e0c4ecf573e4db564355a7100d741
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Thu Dec 1 10:49:44 2022 +0800
[enhancement](Nereids) avoid add project that output same with child to memo (#14180)
---
.../java/org/apache/doris/nereids/memo/Memo.java | 17 ++++++++++++++-
.../org/apache/doris/nereids/memo/MemoTest.java | 8 +++----
.../join/SemiJoinSemiJoinTransposeProjectTest.java | 25 +++++++++-------------
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
index f66bffd3ec..1ecec2d296 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
@@ -27,6 +27,7 @@ import org.apache.doris.nereids.trees.plans.GroupPlan;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.statistics.StatsDeriveResult;
import com.google.common.base.Preconditions;
@@ -283,6 +284,20 @@ public class Memo {
* and the second element is a reference of node in Memo
*/
private CopyInResult doCopyIn(Plan plan, @Nullable Group targetGroup) {
+ // TODO: this is same with EliminateUnnecessaryProject,
+ // we need a infra to rewrite plan after every exploration job
+ if (plan instanceof LogicalProject) {
+ LogicalProject<Plan> logicalProject = (LogicalProject<Plan>) plan;
+ if (targetGroup != root) {
+ if (logicalProject.getOutputSet().equals(logicalProject.child().getOutputSet())) {
+ return doCopyIn(logicalProject.child(), targetGroup);
+ }
+ } else {
+ if (logicalProject.getOutput().equals(logicalProject.child().getOutput())) {
+ return doCopyIn(logicalProject.child(), targetGroup);
+ }
+ }
+ }
// check logicalproperties, must same output in a Group.
if (targetGroup != null && !plan.getLogicalProperties().equals(targetGroup.getLogicalProperties())) {
throw new IllegalStateException("Insert a plan into targetGroup but differ in logicalproperties");
@@ -321,7 +336,7 @@ public class Memo {
validateRewriteChildGroup(childGroup, targetGroup);
childrenGroups.add(childGroup);
} else {
- childrenGroups.add(doRewrite(child, null).correspondingExpression.getOwnerGroup());
+ childrenGroups.add(copyIn(child, null, true).correspondingExpression.getOwnerGroup());
}
}
return childrenGroups;
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
index 1735ecec1f..ef385bd37b 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
@@ -123,11 +123,12 @@ class MemoTest implements PatternMatchSupported {
.transform(
// swap join's children
logicalJoin(logicalOlapScan(), logicalOlapScan()).then(joinBA ->
+ // this project eliminate when copy in, because it's output same with child.
new LogicalProject<>(Lists.newArrayList(joinBA.getOutput()),
new LogicalJoin<>(JoinType.INNER_JOIN, joinBA.right(), joinBA.left()))
))
- .checkGroupNum(6)
- .checkGroupExpressionNum(7)
+ .checkGroupNum(5)
+ .checkGroupExpressionNum(6)
.checkMemo(memo -> {
Group root = memo.getRoot();
Assertions.assertEquals(1, root.getLogicalExpressions().size());
@@ -135,8 +136,7 @@ class MemoTest implements PatternMatchSupported {
Assertions.assertEquals(2, joinABC.child(0).getLogicalExpressions().size());
Assertions.assertEquals(1, joinABC.child(1).getLogicalExpressions().size());
GroupExpression joinAB = joinABC.child(0).getLogicalExpressions().get(0);
- GroupExpression project = joinABC.child(0).getLogicalExpressions().get(1);
- GroupExpression joinBA = project.child(0).getLogicalExpression();
+ GroupExpression joinBA = joinABC.child(0).getLogicalExpressions().get(1);
Assertions.assertTrue(joinAB.getPlan() instanceof LogicalJoin);
Assertions.assertTrue(joinBA.getPlan() instanceof LogicalJoin);
});
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
index 56d80933eb..58b816e329 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
@@ -38,16 +38,16 @@ public class SemiJoinSemiJoinTransposeProjectTest implements PatternMatchSupport
@Test
public void testSemiProjectSemiCommute() {
/*
- * t1.name=t3.name t1.id=t2.id
+ * t1.name=t3.name t1.id=t2.id
* topJoin newTopJoin
- * / \ / \
- * project t3 project t2
- * t1.name t1.name, t1.id
- * | |
- * t1.id=t2.id t1.name=t3.name
- * bottomJoin --> newBottomJoin
- * / \ / \
- * t1 t2 t1 t3
+ * / \ / \
+ * project t3 t1.name=t3.name t2
+ * t1.name --> newBottomJoin
+ * | / \
+ * t1.id=t2.id t1 t3
+ * bottomJoin
+ * / \
+ * t1 t2
*/
LogicalPlan topJoin = new LogicalPlanBuilder(scan1)
.hashJoinUsing(scan2, JoinType.LEFT_ANTI_JOIN, Pair.of(0, 0))
@@ -60,15 +60,10 @@ public class SemiJoinSemiJoinTransposeProjectTest implements PatternMatchSupport
.matchesExploration(
logicalProject(
logicalJoin(
- logicalProject(
logicalJoin(
logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
- ).when(join -> join.getJoinType() == JoinType.LEFT_SEMI_JOIN)
- ).when(project -> project.getProjects().size() == 2
- && project.getProjects().get(0).getName().equals("id")
- && project.getProjects().get(1).getName().equals("name")
- ),
+ ).when(join -> join.getJoinType() == JoinType.LEFT_SEMI_JOIN),
logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2"))
).when(join -> join.getJoinType() == JoinType.LEFT_ANTI_JOIN)
)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org