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 2023/01/05 16:18:16 UTC
[doris] branch master updated: [fix](Nereids): restrict join reorder project. (#15645)
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 6d691edcc7 [fix](Nereids): restrict join reorder project. (#15645)
6d691edcc7 is described below
commit 6d691edcc7887cf92cfb54bd79617b1749a6d3d9
Author: jakevin <ja...@gmail.com>
AuthorDate: Fri Jan 6 00:18:05 2023 +0800
[fix](Nereids): restrict join reorder project. (#15645)
---
.../exploration/join/InnerJoinLAsscomProject.java | 1 +
.../rules/exploration/join/JoinReorderCommon.java | 64 ++++++++++++++++++++++
.../exploration/join/OuterJoinLAsscomProject.java | 1 +
.../join/SemiJoinLogicalJoinTransposeProject.java | 1 +
.../join/SemiJoinSemiJoinTransposeProject.java | 1 +
5 files changed, 68 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
index 67488a0a16..41fc0c4b25 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
@@ -64,6 +64,7 @@ public class InnerJoinLAsscomProject extends OneExplorationRuleFactory {
return innerLogicalJoin(logicalProject(innerLogicalJoin()), group())
.when(topJoin -> InnerJoinLAsscom.checkReorder(topJoin, topJoin.left().child()))
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
+ .when(join -> JoinReorderCommon.checkProject(join.left()))
.then(topJoin -> {
/* ********** init ********** */
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinReorderCommon.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinReorderCommon.java
new file mode 100644
index 0000000000..e5af6a9f38
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinReorderCommon.java
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.exploration.join;
+
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.plans.GroupPlan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Common
+ */
+class JoinReorderCommon {
+ /**
+ * check project inside Join.
+ */
+ static boolean checkProject(LogicalProject<LogicalJoin<GroupPlan, GroupPlan>> project) {
+ Set<Slot> left = project.child().left().getOutputSet();
+ Set<Slot> right = project.child().right().getOutputSet();
+ List<NamedExpression> exprs = project.getProjects();
+ // must be slot or Alias(slot)
+ if (!exprs.stream().allMatch(expr -> {
+ if (expr instanceof Slot) {
+ return true;
+ }
+ if (expr instanceof Alias) {
+ if (((Alias) expr).child() instanceof Slot) {
+ return true;
+ }
+ }
+ return false;
+ })) {
+ return false;
+ }
+
+ // check project exist hyper edge
+ return exprs.stream().allMatch(expr -> {
+ Set<Slot> slots = expr.collect(SlotReference.class::isInstance);
+ return !(ExpressionUtils.isIntersecting(left, slots) && ExpressionUtils.isIntersecting(right, slots));
+ });
+ }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
index a1187f1098..88f7d39777 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
@@ -66,6 +66,7 @@ public class OuterJoinLAsscomProject extends OneExplorationRuleFactory {
Pair.of(join.left().child().getJoinType(), join.getJoinType())))
.when(topJoin -> OuterJoinLAsscom.checkReorder(topJoin, topJoin.left().child()))
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
+ .when(join -> JoinReorderCommon.checkProject(join.left()))
.then(topJoin -> {
/* ********** init ********** */
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTransposeProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTransposeProject.java
index 4559680e37..f49c762e35 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTransposeProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTransposeProject.java
@@ -62,6 +62,7 @@ public class SemiJoinLogicalJoinTransposeProject extends OneExplorationRuleFacto
.whenNot(topJoin -> topJoin.left().child().getJoinType().isSemiOrAntiJoin())
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
.when(this::conditionChecker)
+ .when(join -> JoinReorderCommon.checkProject(join.left()))
.then(topSemiJoin -> {
LogicalProject<LogicalJoin<GroupPlan, GroupPlan>> project = topSemiJoin.left();
LogicalJoin<GroupPlan, GroupPlan> bottomJoin = project.child();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProject.java
index 448cef7221..ac9be2fda6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProject.java
@@ -54,6 +54,7 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory
.when(this::typeChecker)
.when(topSemi -> InnerJoinLAsscom.checkReorder(topSemi, topSemi.left().child()))
.whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
+ .when(join -> JoinReorderCommon.checkProject(join.left()))
.then(topSemi -> {
LogicalJoin<GroupPlan, GroupPlan> bottomSemi = topSemi.left().child();
LogicalProject abProject = topSemi.left();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org