diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java index af6daa2efe..f69413309d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java @@ -263,7 +263,7 @@ public enum RuleType { LOGICAL_WINDOW_TO_PHYSICAL_WINDOW_RULE(RuleTypeClass.IMPLEMENTATION), IMPLEMENTATION_SENTINEL(RuleTypeClass.IMPLEMENTATION), - LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANPOSE_PROJECT(RuleTypeClass.EXPLORATION), + LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANSPOSE_PROJECT(RuleTypeClass.EXPLORATION), // sentinel, use to count rules SENTINEL(RuleTypeClass.SENTINEL), ; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java index 977ef42afa..a16b7b91c1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java @@ -23,8 +23,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; -import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.Utils; @@ -77,15 +75,15 @@ public class InnerJoinLAsscom extends OneExplorationRuleFactory { List newTopOtherConjuncts = splitOtherConjunts.get(true); List newBottomOtherConjuncts = splitOtherConjunts.get(false); - LogicalJoin newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN, - newBottomHashConjuncts, newBottomOtherConjuncts, JoinHint.NONE, - a, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren(newBottomHashConjuncts, + newBottomOtherConjuncts, a, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasLAsscom(false); newBottomJoin.getJoinReorderContext().setHasCommute(false); - LogicalJoin, GroupPlan> newTopJoin = new LogicalJoin<>( - JoinType.INNER_JOIN, newTopHashConjuncts, newTopOtherConjuncts, JoinHint.NONE, - newBottomJoin, b, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren(newTopHashConjuncts, + newTopOtherConjuncts, newBottomJoin, b); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasLAsscom(true); return newTopJoin; 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 aac195cb3a..bc8656520f 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 @@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.Utils; @@ -104,18 +103,18 @@ public class InnerJoinLAsscomProject extends OneExplorationRuleFactory { aProjects.addAll(cOutputSet); /* ********** new Plan ********** */ - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - helper.newBottomHashConjuncts, helper.newBottomOtherConjuncts, JoinHint.NONE, - a, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren(helper.newBottomHashConjuncts, + helper.newBottomOtherConjuncts, a, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasLAsscom(false); newBottomJoin.getJoinReorderContext().setHasCommute(false); Plan left = JoinReorderUtils.projectOrSelf(aProjects, newBottomJoin); Plan right = JoinReorderUtils.projectOrSelf(bProjects, b); - LogicalJoin newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(), - helper.newTopHashConjuncts, helper.newTopOtherConjuncts, JoinHint.NONE, - left, right, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren(helper.newTopHashConjuncts, + helper.newTopOtherConjuncts, left, right); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasLAsscom(true); return JoinReorderUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()), newTopJoin); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociate.java index 9a210cb91d..2f89495365 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociate.java @@ -23,8 +23,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; -import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.JoinUtils; @@ -90,17 +88,17 @@ public class InnerJoinLeftAssociate extends OneExplorationRuleFactory { List newTopOtherJoinConjuncts = otherConjunctsSplit.get(false); // new join. - LogicalJoin newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN, - newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, JoinHint.NONE, - a, b, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren( + newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, a, b); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasCommute(false); newBottomJoin.getJoinReorderContext().setHasRightAssociate(false); newBottomJoin.getJoinReorderContext().setHasLeftAssociate(false); newBottomJoin.getJoinReorderContext().setHasExchange(false); - LogicalJoin, GroupPlan> newTopJoin = new LogicalJoin<>( - JoinType.INNER_JOIN, newTopHashJoinConjuncts, newTopOtherJoinConjuncts, JoinHint.NONE, - newBottomJoin, c, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren( + newTopHashJoinConjuncts, newTopOtherJoinConjuncts, newBottomJoin, c); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasLeftAssociate(true); newTopJoin.getJoinReorderContext().setHasCommute(false); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociate.java index afa307f5b1..b6ea7d2ad7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociate.java @@ -23,8 +23,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; -import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.JoinUtils; @@ -88,17 +86,17 @@ public class InnerJoinRightAssociate extends OneExplorationRuleFactory { List newBottomOtherJoinConjuncts = otherConjunctsSplit.get(true); List newTopOtherJoinConjuncts = otherConjunctsSplit.get(false); - LogicalJoin newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN, - newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, JoinHint.NONE, - b, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren( + newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, b, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasCommute(false); newBottomJoin.getJoinReorderContext().setHasRightAssociate(false); newBottomJoin.getJoinReorderContext().setHasLeftAssociate(false); newBottomJoin.getJoinReorderContext().setHasExchange(false); - LogicalJoin> newTopJoin = new LogicalJoin<>( - JoinType.INNER_JOIN, newTopHashJoinConjuncts, newTopOtherJoinConjuncts, JoinHint.NONE, - a, newBottomJoin, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren(newTopHashJoinConjuncts, + newTopOtherJoinConjuncts, a, newBottomJoin); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasRightAssociate(true); newTopJoin.getJoinReorderContext().setHasCommute(false); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommute.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommute.java index 3c89dcd681..7b5b1c8a45 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommute.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommute.java @@ -22,7 +22,6 @@ import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import java.util.List; @@ -52,9 +51,9 @@ public class JoinCommute extends OneExplorationRuleFactory { join.getJoinType().swap(), join.getHashJoinConjuncts(), join.getOtherJoinConjuncts(), - JoinHint.NONE, - join.right(), join.left(), - join.getJoinReorderContext()); + join.getHint(), + join.right(), join.left()); + newJoin.getJoinReorderContext().copyFrom(join.getJoinReorderContext()); newJoin.getJoinReorderContext().setHasCommute(true); if (swapType == SwapType.ZIG_ZAG && isNotBottomJoin(join)) { newJoin.getJoinReorderContext().setHasCommuteZigZag(true); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchange.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchange.java index 568492c3c1..e95bd2310a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchange.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchange.java @@ -86,7 +86,8 @@ public class JoinExchange extends OneExplorationRuleFactory { } LogicalJoin newLeftJoin = new LogicalJoin<>(JoinType.INNER_JOIN, newLeftJoinHashJoinConjuncts, newLeftJoinOtherJoinConjuncts, JoinHint.NONE, - a, c, leftJoin.getJoinReorderContext()); + a, c); + newLeftJoin.getJoinReorderContext().copyFrom(leftJoin.getJoinReorderContext()); newLeftJoin.getJoinReorderContext().setHasCommute(false); newLeftJoin.getJoinReorderContext().setHasLeftAssociate(false); newLeftJoin.getJoinReorderContext().setHasRightAssociate(false); @@ -94,7 +95,8 @@ public class JoinExchange extends OneExplorationRuleFactory { LogicalJoin newRightJoin = new LogicalJoin<>(JoinType.INNER_JOIN, newRightJoinHashJoinConjuncts, newRightJoinOtherJoinConjuncts, JoinHint.NONE, - b, d, rightJoin.getJoinReorderContext()); + b, d); + newRightJoin.getJoinReorderContext().copyFrom(leftJoin.getJoinReorderContext()); newRightJoin.getJoinReorderContext().setHasCommute(false); newRightJoin.getJoinReorderContext().setHasLeftAssociate(false); newRightJoin.getJoinReorderContext().setHasRightAssociate(false); @@ -103,7 +105,8 @@ public class JoinExchange extends OneExplorationRuleFactory { LogicalJoin, LogicalJoin> newTopJoin = new LogicalJoin<>(JoinType.INNER_JOIN, newTopJoinHashJoinConjuncts, newTopJoinOtherJoinConjuncts, JoinHint.NONE, - newLeftJoin, newRightJoin, topJoin.getJoinReorderContext()); + newLeftJoin, newRightJoin); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasExchange(true); return newTopJoin; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssoc.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssoc.java index 05229d2bcb..acb3549562 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssoc.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssoc.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; 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.JoinHint; import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; @@ -70,13 +69,10 @@ public class OuterJoinAssoc extends OneExplorationRuleFactory { * But because we have added eliminate_outer_rule, we don't need to consider this. */ - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - topJoin.getHashJoinConjuncts(), topJoin.getOtherJoinConjuncts(), JoinHint.NONE, - b, c); - LogicalJoin> newTopJoin - = new LogicalJoin<>(bottomJoin.getJoinType(), - bottomJoin.getHashJoinConjuncts(), bottomJoin.getOtherJoinConjuncts(), JoinHint.NONE, - a, newBottomJoin, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(b, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(a, newBottomJoin); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); setReorderContext(newTopJoin, newBottomJoin); return newTopJoin; }).toRule(RuleType.LOGICAL_OUTER_JOIN_ASSOC); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java index 7faafbbac5..c18d4f2383 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.Utils; @@ -93,16 +92,16 @@ public class OuterJoinAssocProject extends OneExplorationRuleFactory { bProjects.addAll(OuterJoinLAsscomProject.forceToNullable(c.getOutputSet())); /* ********** new Plan ********** */ - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - helper.newBottomHashConjuncts, helper.newBottomOtherConjuncts, JoinHint.NONE, - b, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren(helper.newBottomHashConjuncts, + helper.newBottomOtherConjuncts, b, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); Plan left = JoinReorderUtils.projectOrSelf(aProjects, a); Plan right = JoinReorderUtils.projectOrSelf(bProjects, newBottomJoin); - LogicalJoin newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(), - helper.newTopHashConjuncts, helper.newTopOtherConjuncts, JoinHint.NONE, - left, right, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren(helper.newTopHashConjuncts, + helper.newTopOtherConjuncts, left, right); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); OuterJoinAssoc.setReorderContext(newTopJoin, newBottomJoin); return JoinReorderUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()), newTopJoin); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java index a23c3f0015..acf3a7e30c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; @@ -71,16 +70,13 @@ public class OuterJoinLAsscom extends OneExplorationRuleFactory { GroupPlan b = bottomJoin.right(); GroupPlan c = topJoin.right(); - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - topJoin.getHashJoinConjuncts(), topJoin.getOtherJoinConjuncts(), JoinHint.NONE, - a, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(a, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasLAsscom(false); newBottomJoin.getJoinReorderContext().setHasCommute(false); - LogicalJoin, GroupPlan> newTopJoin = new LogicalJoin<>( - bottomJoin.getJoinType(), - bottomJoin.getHashJoinConjuncts(), bottomJoin.getOtherJoinConjuncts(), JoinHint.NONE, - newBottomJoin, b, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(newBottomJoin, b); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasLAsscom(true); return newTopJoin; 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 6bfa65b353..2562e6045a 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 @@ -26,7 +26,6 @@ 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.JoinHint; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.Utils; @@ -98,19 +97,20 @@ public class OuterJoinLAsscomProject extends OneExplorationRuleFactory { aProjects.addAll(forceToNullable(c.getOutputSet())); /* ********** new Plan ********** */ - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - helper.newBottomHashConjuncts, helper.newBottomOtherConjuncts, JoinHint.NONE, - a, c, bottomJoin.getJoinReorderContext()); + LogicalJoin newBottomJoin = topJoin.withConjunctsChildren(helper.newBottomHashConjuncts, + helper.newBottomOtherConjuncts, a, c); + newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext()); newBottomJoin.getJoinReorderContext().setHasLAsscom(false); newBottomJoin.getJoinReorderContext().setHasCommute(false); Plan left = JoinReorderUtils.projectOrSelf(aProjects, newBottomJoin); Plan right = JoinReorderUtils.projectOrSelf(bProjects, b); - LogicalJoin newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(), - helper.newTopHashConjuncts, helper.newTopOtherConjuncts, JoinHint.NONE, - left, right, topJoin.getJoinReorderContext()); + LogicalJoin newTopJoin = bottomJoin.withConjunctsChildren(helper.newTopHashConjuncts, + helper.newTopOtherConjuncts, left, right); + newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext()); newTopJoin.getJoinReorderContext().setHasLAsscom(true); + return JoinReorderUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()), newTopJoin); }).toRule(RuleType.LOGICAL_OUTER_JOIN_LASSCOM_PROJECT); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTranspose.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTranspose.java index 79b79510b3..cbefea40f6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTranspose.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinLogicalJoinTranspose.java @@ -23,8 +23,8 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.JoinType; +import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.util.Utils; @@ -84,19 +84,11 @@ public class SemiJoinLogicalJoinTranspose extends OneExplorationRuleFactory { * / \ / \ * A B A C */ - if (bottomJoin.getJoinType() == JoinType.RIGHT_OUTER_JOIN) { - // when bottom join is right outer join, we change it to inner join - // if we want to do this trans. However, we do not allow different logical properties - // in one group. So we need to change it to inner join in rewrite step. - return topSemiJoin; - } - LogicalJoin newBottomSemiJoin = new LogicalJoin<>( - topSemiJoin.getJoinType(), - topSemiJoin.getHashJoinConjuncts(), topSemiJoin.getOtherJoinConjuncts(), - JoinHint.NONE, - a, c); - return new LogicalJoin<>(bottomJoin.getJoinType(), bottomJoin.getHashJoinConjuncts(), - bottomJoin.getOtherJoinConjuncts(), JoinHint.NONE, newBottomSemiJoin, b); + // RIGHT_OUTER_JOIN should be eliminated in rewrite phase + Preconditions.checkState(bottomJoin.getJoinType() != JoinType.RIGHT_OUTER_JOIN); + + Plan newBottomSemiJoin = topSemiJoin.withChildren(a, c); + return bottomJoin.withChildren(newBottomSemiJoin, b); } else { /* * topSemiJoin newTopJoin @@ -105,19 +97,11 @@ public class SemiJoinLogicalJoinTranspose extends OneExplorationRuleFactory { * / \ / \ * A B B C */ - if (bottomJoin.getJoinType() == JoinType.LEFT_OUTER_JOIN) { - // when bottom join is left outer join, we change it to inner join - // if we want to do this trans. However, we do not allow different logical properties - // in one group. So we need to change it to inner join in rewrite step. - return topSemiJoin; - } - LogicalJoin newBottomSemiJoin = new LogicalJoin<>( - topSemiJoin.getJoinType(), - topSemiJoin.getHashJoinConjuncts(), topSemiJoin.getOtherJoinConjuncts(), - JoinHint.NONE, - b, c); - return new LogicalJoin<>(bottomJoin.getJoinType(), bottomJoin.getHashJoinConjuncts(), - bottomJoin.getOtherJoinConjuncts(), JoinHint.NONE, a, newBottomSemiJoin); + // LEFT_OUTER_JOIN should be eliminated in rewrite phase + Preconditions.checkState(bottomJoin.getJoinType() != JoinType.LEFT_OUTER_JOIN); + + Plan newBottomSemiJoin = topSemiJoin.withChildren(b, c); + return bottomJoin.withChildren(a, newBottomSemiJoin); } }).toRule(RuleType.LOGICAL_SEMI_JOIN_LOGICAL_JOIN_TRANSPOSE); } 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 89a843fffc..aefba5aace 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 @@ -26,7 +26,6 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; @@ -96,19 +95,12 @@ public class SemiJoinLogicalJoinTransposeProject extends OneExplorationRuleFacto * / \ / \ * A B A C */ - // Preconditions.checkState(bottomJoin.getJoinType() != JoinType.RIGHT_OUTER_JOIN); - if (bottomJoin.getJoinType() == JoinType.RIGHT_OUTER_JOIN) { - // when bottom join is right outer join, we change it to inner join - // if we want to do this trans. However, we do not allow different logical properties - // in one group. So we need to change it to inner join in rewrite step. - return null; - } - LogicalJoin newBottomSemiJoin = new LogicalJoin<>( - topSemiJoin.getJoinType(), conjuncts.first, conjuncts.second, JoinHint.NONE, a, c); + // RIGHT_OUTER_JOIN should be eliminated in rewrite phase + Preconditions.checkState(bottomJoin.getJoinType() != JoinType.RIGHT_OUTER_JOIN); - LogicalJoin newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(), - bottomJoin.getHashJoinConjuncts(), bottomJoin.getOtherJoinConjuncts(), - JoinHint.NONE, newBottomSemiJoin, b); + Plan newBottomSemiJoin = topSemiJoin.withConjunctsChildren(conjuncts.first, conjuncts.second, + a, c); + Plan newTopJoin = bottomJoin.withChildren(newBottomSemiJoin, b); return project.withChildren(newTopJoin); } else { if (leftDeep) { @@ -123,18 +115,12 @@ public class SemiJoinLogicalJoinTransposeProject extends OneExplorationRuleFacto * / \ / \ * A B B C */ - if (bottomJoin.getJoinType() == JoinType.LEFT_OUTER_JOIN) { - // when bottom join is left outer join, we change it to inner join - // if we want to do this trans. However, we do not allow different logical properties - // in one group. So we need to change it to inner join in rewrite step. - return null; - } - LogicalJoin newBottomSemiJoin = new LogicalJoin<>( - topSemiJoin.getJoinType(), conjuncts.first, conjuncts.second, JoinHint.NONE, b, c); + // LEFT_OUTER_JOIN should be eliminated in rewrite phase + Preconditions.checkState(bottomJoin.getJoinType() != JoinType.LEFT_OUTER_JOIN); - LogicalJoin newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(), - bottomJoin.getHashJoinConjuncts(), bottomJoin.getOtherJoinConjuncts(), - JoinHint.NONE, a, newBottomSemiJoin); + Plan newBottomSemiJoin = topSemiJoin.withConjunctsChildren(conjuncts.first, conjuncts.second, + b, c); + Plan newTopJoin = bottomJoin.withChildren(a, newBottomSemiJoin); return project.withChildren(newTopJoin); } }).toRule(RuleType.LOGICAL_SEMI_JOIN_LOGICAL_JOIN_TRANSPOSE_PROJECT); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTranspose.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTranspose.java index e616bc7397..f2e5c50aee 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTranspose.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTranspose.java @@ -22,8 +22,8 @@ import org.apache.doris.nereids.rules.Rule; import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.JoinType; +import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import com.google.common.collect.ImmutableSet; @@ -69,14 +69,8 @@ public class SemiJoinSemiJoinTranspose extends OneExplorationRuleFactory { GroupPlan b = bottomJoin.right(); GroupPlan c = topJoin.right(); - LogicalJoin newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(), - topJoin.getHashJoinConjuncts(), topJoin.getOtherJoinConjuncts(), JoinHint.NONE, a, c); - LogicalJoin, GroupPlan> newTopJoin = new LogicalJoin<>( - bottomJoin.getJoinType(), bottomJoin.getHashJoinConjuncts(), - bottomJoin.getOtherJoinConjuncts(), - JoinHint.NONE, - newBottomJoin, b); - + Plan newBottomJoin = topJoin.withChildren(a, c); + Plan newTopJoin = bottomJoin.withChildren(newBottomJoin, b); return newTopJoin; }).toRule(RuleType.LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANPOSE); } 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 3e86b5b17e..734108c4db 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 @@ -24,7 +24,6 @@ import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.plans.GroupPlan; -import org.apache.doris.nereids.trees.plans.JoinHint; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.trees.plans.logical.LogicalProject; @@ -42,9 +41,9 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory /* * topSemi newTopSemi - * / \ / \ - * abProject C acProject B - * / ──► / + * / \ / \ + * aProject C aProject B + * | ──► | * bottomSemi newBottomSemi * / \ / \ * A B A C @@ -73,18 +72,17 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory } }) ); - LogicalJoin newBottomSemi = new LogicalJoin<>(topSemi.getJoinType(), topSemi.getHashJoinConjuncts(), - topSemi.getOtherJoinConjuncts(), JoinHint.NONE, a, c, - bottomSemi.getJoinReorderContext()); + LogicalJoin newBottomSemi = (LogicalJoin) topSemi.withChildren(a, c); + newBottomSemi.getJoinReorderContext().copyFrom(bottomSemi.getJoinReorderContext()); newBottomSemi.getJoinReorderContext().setHasCommute(false); newBottomSemi.getJoinReorderContext().setHasLAsscom(false); + LogicalProject acProject = new LogicalProject<>(Lists.newArrayList(acProjects), newBottomSemi); - LogicalJoin newTopSemi = new LogicalJoin<>(bottomSemi.getJoinType(), - bottomSemi.getHashJoinConjuncts(), bottomSemi.getOtherJoinConjuncts(), JoinHint.NONE, - acProject, b, topSemi.getJoinReorderContext()); + LogicalJoin newTopSemi = (LogicalJoin) bottomSemi.withChildren(acProject, b); + newTopSemi.getJoinReorderContext().copyFrom(topSemi.getJoinReorderContext()); newTopSemi.getJoinReorderContext().setHasLAsscom(true); return JoinReorderUtils.projectOrSelf(new ArrayList<>(topSemi.getOutput()), newTopSemi); - }).toRule(RuleType.LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANPOSE_PROJECT); + }).toRule(RuleType.LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANSPOSE_PROJECT); } public boolean typeChecker(LogicalJoin>, GroupPlan> topJoin) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java index bd4f8505f6..9847c0e316 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java @@ -57,73 +57,39 @@ public class LogicalJoin hashJoinConjuncts, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { this(joinType, hashJoinConjuncts, ExpressionUtils.EMPTY_CONDITION, JoinHint.NONE, Optional.empty(), - Optional.empty(), leftChild, rightChild, JoinReorderContext.EMPTY, false); + Optional.empty(), leftChild, rightChild, false); } - public LogicalJoin( - JoinType joinType, - List hashJoinConjuncts, - List otherJoinConjuncts, - JoinHint hint, - LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { - this(joinType, hashJoinConjuncts, - otherJoinConjuncts, hint, Optional.empty(), Optional.empty(), leftChild, rightChild, - JoinReorderContext.EMPTY, false); - } - - public LogicalJoin( - JoinType joinType, - List hashJoinConjuncts, - JoinHint hint, - LEFT_CHILD_TYPE leftChild, - RIGHT_CHILD_TYPE rightChild, - JoinReorderContext joinReorderContext) { - this(joinType, hashJoinConjuncts, ExpressionUtils.EMPTY_CONDITION, hint, - Optional.empty(), Optional.empty(), leftChild, rightChild, joinReorderContext, false); - } - - public LogicalJoin( - JoinType joinType, - List hashJoinConjuncts, - List otherJoinConjuncts, - JoinHint hint, - LEFT_CHILD_TYPE leftChild, - RIGHT_CHILD_TYPE rightChild, - JoinReorderContext joinReorderContext) { + public LogicalJoin(JoinType joinType, List hashJoinConjuncts, List otherJoinConjuncts, + JoinHint hint, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) { this(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, Optional.empty(), Optional.empty(), leftChild, - rightChild, joinReorderContext, false); - } - - public LogicalJoin( - JoinType joinType, - List hashJoinConjuncts, - List otherJoinConjuncts, - JoinHint hint, - LEFT_CHILD_TYPE leftChild, - RIGHT_CHILD_TYPE rightChild, - JoinReorderContext joinReorderContext, - boolean isGenerateIsNotNull) { - this(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, Optional.empty(), Optional.empty(), leftChild, - rightChild, joinReorderContext, isGenerateIsNotNull); + rightChild, false); } /** - * Constructor for LogicalJoinPlan. + * Just use in withXXX method. */ - public LogicalJoin( + private LogicalJoin(JoinType joinType, List hashJoinConjuncts, List otherJoinConjuncts, + JoinHint hint, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild, + JoinReorderContext joinReorderContext, boolean isGenerateIsNotNull) { + super(PlanType.LOGICAL_JOIN, Optional.empty(), Optional.empty(), leftChild, rightChild); + this.joinType = Objects.requireNonNull(joinType, "joinType can not be null"); + this.hashJoinConjuncts = ImmutableList.copyOf(hashJoinConjuncts); + this.otherJoinConjuncts = ImmutableList.copyOf(otherJoinConjuncts); + this.hint = Objects.requireNonNull(hint, "hint can not be null"); + this.isGenerateIsNotNull = isGenerateIsNotNull; + this.joinReorderContext.copyFrom(joinReorderContext); + } + + private LogicalJoin( JoinType joinType, List hashJoinConjuncts, List otherJoinConjuncts, @@ -132,14 +98,12 @@ public class LogicalJoin logicalProperties, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild, - JoinReorderContext joinReorderContext, boolean isGenerateIsNotNull) { super(PlanType.LOGICAL_JOIN, groupExpression, logicalProperties, leftChild, rightChild); this.joinType = Objects.requireNonNull(joinType, "joinType can not be null"); this.hashJoinConjuncts = ImmutableList.copyOf(hashJoinConjuncts); this.otherJoinConjuncts = ImmutableList.copyOf(otherJoinConjuncts); this.hint = Objects.requireNonNull(hint, "hint can not be null"); - this.joinReorderContext.copyFrom(joinReorderContext); this.isGenerateIsNotNull = isGenerateIsNotNull; } @@ -244,14 +208,18 @@ public class LogicalJoin withGroupExpression(Optional groupExpression) { - return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, groupExpression, - Optional.of(getLogicalProperties()), left(), right(), joinReorderContext, isGenerateIsNotNull); + LogicalJoin newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, + groupExpression, Optional.of(getLogicalProperties()), left(), right(), isGenerateIsNotNull); + newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext()); + return newJoin; } @Override public LogicalJoin withLogicalProperties(Optional logicalProperties) { - return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, Optional.empty(), - logicalProperties, left(), right(), joinReorderContext, isGenerateIsNotNull); + LogicalJoin newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, + Optional.empty(), logicalProperties, left(), right(), isGenerateIsNotNull); + newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext()); + return newJoin; } public LogicalJoin withHashJoinConjuncts(List hashJoinConjuncts) { @@ -272,6 +240,12 @@ public class LogicalJoin withConjunctsChildren(List hashJoinConjuncts, + List otherJoinConjuncts, Plan left, Plan right) { + return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left, + right, joinReorderContext, isGenerateIsNotNull); + } + public LogicalJoin withJoinType(JoinType joinType) { return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left(), right(), joinReorderContext, isGenerateIsNotNull); @@ -284,7 +258,7 @@ public class LogicalJoin withIsGenerateIsNotNullAndChildren(boolean isGenerateIsNotNull, Plan left, Plan right) { - return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, Optional.empty(), - Optional.empty(), left, right, joinReorderContext, isGenerateIsNotNull); + return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left, + right, joinReorderContext, isGenerateIsNotNull); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/LogicalPlanBuilder.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/LogicalPlanBuilder.java index 04da2c6bae..c719302ac5 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/LogicalPlanBuilder.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/LogicalPlanBuilder.java @@ -73,6 +73,11 @@ public class LogicalPlanBuilder { return from(project); } + public LogicalPlanBuilder projectExprs(List projectExprs) { + LogicalProject project = new LogicalProject<>(projectExprs, this.plan); + return from(project); + } + public LogicalPlanBuilder alias(List slotsIndex, List alias) { Preconditions.checkArgument(slotsIndex.size() == alias.size());