[enhance](Nereids): refactor LogicalJoin. (#17099)

This commit is contained in:
jakevin
2023-02-26 22:28:54 +08:00
committed by GitHub
parent 7cb6c522b0
commit 710529b060
17 changed files with 128 additions and 201 deletions

View File

@ -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),
;

View File

@ -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<Expression> newTopOtherConjuncts = splitOtherConjunts.get(true);
List<Expression> newBottomOtherConjuncts = splitOtherConjunts.get(false);
LogicalJoin<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN,
newBottomHashConjuncts, newBottomOtherConjuncts, JoinHint.NONE,
a, c, bottomJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> newBottomJoin = topJoin.withConjunctsChildren(newBottomHashConjuncts,
newBottomOtherConjuncts, a, c);
newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext());
newBottomJoin.getJoinReorderContext().setHasLAsscom(false);
newBottomJoin.getJoinReorderContext().setHasCommute(false);
LogicalJoin<LogicalJoin<GroupPlan, GroupPlan>, GroupPlan> newTopJoin = new LogicalJoin<>(
JoinType.INNER_JOIN, newTopHashConjuncts, newTopOtherConjuncts, JoinHint.NONE,
newBottomJoin, b, topJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> newTopJoin = bottomJoin.withConjunctsChildren(newTopHashConjuncts,
newTopOtherConjuncts, newBottomJoin, b);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
newTopJoin.getJoinReorderContext().setHasLAsscom(true);
return newTopJoin;

View File

@ -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<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(),
helper.newBottomHashConjuncts, helper.newBottomOtherConjuncts, JoinHint.NONE,
a, c, bottomJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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<Plan, Plan> newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(),
helper.newTopHashConjuncts, helper.newTopOtherConjuncts, JoinHint.NONE,
left, right, topJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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);

View File

@ -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<Expression> newTopOtherJoinConjuncts = otherConjunctsSplit.get(false);
// new join.
LogicalJoin<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN,
newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, JoinHint.NONE,
a, b, bottomJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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<LogicalJoin<GroupPlan, GroupPlan>, GroupPlan> newTopJoin = new LogicalJoin<>(
JoinType.INNER_JOIN, newTopHashJoinConjuncts, newTopOtherJoinConjuncts, JoinHint.NONE,
newBottomJoin, c, topJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> newTopJoin = bottomJoin.withConjunctsChildren(
newTopHashJoinConjuncts, newTopOtherJoinConjuncts, newBottomJoin, c);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
newTopJoin.getJoinReorderContext().setHasLeftAssociate(true);
newTopJoin.getJoinReorderContext().setHasCommute(false);

View File

@ -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<Expression> newBottomOtherJoinConjuncts = otherConjunctsSplit.get(true);
List<Expression> newTopOtherJoinConjuncts = otherConjunctsSplit.get(false);
LogicalJoin<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(JoinType.INNER_JOIN,
newBottomHashJoinConjuncts, newBottomOtherJoinConjuncts, JoinHint.NONE,
b, c, bottomJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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<GroupPlan, LogicalJoin<GroupPlan, GroupPlan>> newTopJoin = new LogicalJoin<>(
JoinType.INNER_JOIN, newTopHashJoinConjuncts, newTopOtherJoinConjuncts, JoinHint.NONE,
a, newBottomJoin, topJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> newTopJoin = bottomJoin.withConjunctsChildren(newTopHashJoinConjuncts,
newTopOtherJoinConjuncts, a, newBottomJoin);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
newTopJoin.getJoinReorderContext().setHasRightAssociate(true);
newTopJoin.getJoinReorderContext().setHasCommute(false);

View File

@ -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);

View File

@ -86,7 +86,8 @@ public class JoinExchange extends OneExplorationRuleFactory {
}
LogicalJoin<GroupPlan, GroupPlan> 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<GroupPlan, GroupPlan> 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<GroupPlan, GroupPlan>, LogicalJoin<GroupPlan, GroupPlan>>
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;

View File

@ -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<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(),
topJoin.getHashJoinConjuncts(), topJoin.getOtherJoinConjuncts(), JoinHint.NONE,
b, c);
LogicalJoin<GroupPlan, LogicalJoin<GroupPlan, GroupPlan>> 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);

View File

@ -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<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(),
helper.newBottomHashConjuncts, helper.newBottomOtherConjuncts, JoinHint.NONE,
b, c, bottomJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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<Plan, Plan> newTopJoin = new LogicalJoin<>(bottomJoin.getJoinType(),
helper.newTopHashConjuncts, helper.newTopOtherConjuncts, JoinHint.NONE,
left, right, topJoin.getJoinReorderContext());
LogicalJoin<Plan, Plan> 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);

View File

@ -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<GroupPlan, GroupPlan> 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<LogicalJoin<GroupPlan, GroupPlan>, 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;

View File

@ -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<GroupPlan, GroupPlan> 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<Plan, Plan> 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);
}

View File

@ -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<GroupPlan, GroupPlan> 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<GroupPlan, GroupPlan> 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);
}

View File

@ -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<GroupPlan, GroupPlan> 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<Plan, Plan> 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<GroupPlan, GroupPlan> 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<Plan, Plan> 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);

View File

@ -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<GroupPlan, GroupPlan> newBottomJoin = new LogicalJoin<>(topJoin.getJoinType(),
topJoin.getHashJoinConjuncts(), topJoin.getOtherJoinConjuncts(), JoinHint.NONE, a, c);
LogicalJoin<LogicalJoin<GroupPlan, GroupPlan>, 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);
}

View File

@ -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<LogicalProject<LogicalJoin<GroupPlan, GroupPlan>>, GroupPlan> topJoin) {

View File

@ -57,73 +57,39 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
private final boolean isGenerateIsNotNull;
/**
* Constructor for LogicalJoinPlan.
*
* @param joinType logical type for join
*/
public LogicalJoin(JoinType joinType, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild) {
this(joinType, ExpressionUtils.EMPTY_CONDITION, ExpressionUtils.EMPTY_CONDITION, JoinHint.NONE,
Optional.empty(), Optional.empty(), leftChild, rightChild, JoinReorderContext.EMPTY, false);
Optional.empty(), Optional.empty(), leftChild, rightChild, false);
}
public LogicalJoin(JoinType joinType, List<Expression> 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<Expression> hashJoinConjuncts,
List<Expression> 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<Expression> 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<Expression> hashJoinConjuncts,
List<Expression> otherJoinConjuncts,
JoinHint hint,
LEFT_CHILD_TYPE leftChild,
RIGHT_CHILD_TYPE rightChild,
JoinReorderContext joinReorderContext) {
public LogicalJoin(JoinType joinType, List<Expression> hashJoinConjuncts, List<Expression> 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<Expression> hashJoinConjuncts,
List<Expression> 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<Expression> hashJoinConjuncts, List<Expression> 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<Expression> hashJoinConjuncts,
List<Expression> otherJoinConjuncts,
@ -132,14 +98,12 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
Optional<LogicalProperties> 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<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
@Override
public LogicalJoin<Plan, Plan> withGroupExpression(Optional<GroupExpression> groupExpression) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, groupExpression,
Optional.of(getLogicalProperties()), left(), right(), joinReorderContext, isGenerateIsNotNull);
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
groupExpression, Optional.of(getLogicalProperties()), left(), right(), isGenerateIsNotNull);
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
}
@Override
public LogicalJoin<Plan, Plan> withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, Optional.empty(),
logicalProperties, left(), right(), joinReorderContext, isGenerateIsNotNull);
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
Optional.empty(), logicalProperties, left(), right(), isGenerateIsNotNull);
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
}
public LogicalJoin<Plan, Plan> withHashJoinConjuncts(List<Expression> hashJoinConjuncts) {
@ -272,6 +240,12 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
children.get(1), joinReorderContext, isGenerateIsNotNull);
}
public LogicalJoin<Plan, Plan> withConjunctsChildren(List<Expression> hashJoinConjuncts,
List<Expression> otherJoinConjuncts, Plan left, Plan right) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left,
right, joinReorderContext, isGenerateIsNotNull);
}
public LogicalJoin<Plan, Plan> withJoinType(JoinType joinType) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left(), right(),
joinReorderContext, isGenerateIsNotNull);
@ -284,7 +258,7 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
public LogicalJoin<Plan, Plan> 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);
}
}

View File

@ -73,6 +73,11 @@ public class LogicalPlanBuilder {
return from(project);
}
public LogicalPlanBuilder projectExprs(List<NamedExpression> projectExprs) {
LogicalProject<LogicalPlan> project = new LogicalProject<>(projectExprs, this.plan);
return from(project);
}
public LogicalPlanBuilder alias(List<Integer> slotsIndex, List<String> alias) {
Preconditions.checkArgument(slotsIndex.size() == alias.size());