[fix](Nereids): fix JoinReorderContext in withXXX() of LogicalJoin. (#18299)

This commit is contained in:
jakevin
2023-04-01 16:51:27 +08:00
committed by GitHub
parent 365867a867
commit 9e087622ab
12 changed files with 48 additions and 59 deletions

View File

@ -393,7 +393,7 @@ public class Memo {
validateRewriteChildGroup(childGroup, targetGroup);
childrenGroups.add(childGroup);
} else {
childrenGroups.add(copyIn(child, null, true).correspondingExpression.getOwnerGroup());
childrenGroups.add(doRewrite(child, null).correspondingExpression.getOwnerGroup());
}
}
return childrenGroups;

View File

@ -51,8 +51,8 @@ public class LogicalJoinSemiJoinTranspose implements ExplorationRuleFactory {
GroupPlan b = bottomJoin.right();
GroupPlan c = topJoin.right();
Plan newBottomJoin = topJoin.withChildren(a, c);
return bottomJoin.withChildren(newBottomJoin, b);
Plan newBottomJoin = topJoin.withChildrenNoContext(a, c);
return bottomJoin.withChildrenNoContext(newBottomJoin, b);
}).toRule(RuleType.LOGICAL_JOIN_LOGICAL_SEMI_JOIN_TRANSPOSE),
logicalJoin(group(), logicalJoin())
@ -67,8 +67,8 @@ public class LogicalJoinSemiJoinTranspose implements ExplorationRuleFactory {
GroupPlan b = bottomJoin.left();
GroupPlan c = bottomJoin.right();
Plan newBottomJoin = topJoin.withChildren(a, b);
return bottomJoin.withChildren(newBottomJoin, c);
Plan newBottomJoin = topJoin.withChildrenNoContext(a, b);
return bottomJoin.withChildrenNoContext(newBottomJoin, c);
}).toRule(RuleType.LOGICAL_JOIN_LOGICAL_SEMI_JOIN_TRANSPOSE)
);
}

View File

@ -53,8 +53,8 @@ public class LogicalJoinSemiJoinTransposeProject implements ExplorationRuleFacto
GroupPlan c = topJoin.right();
// Discard this project, because it is useless.
Plan newBottomJoin = topJoin.withChildren(a, c);
Plan newTopJoin = bottomJoin.withChildren(newBottomJoin, b);
Plan newBottomJoin = topJoin.withChildrenNoContext(a, c);
Plan newTopJoin = bottomJoin.withChildrenNoContext(newBottomJoin, b);
return JoinReorderUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()),
newTopJoin);
}).toRule(RuleType.LOGICAL_JOIN_LOGICAL_SEMI_JOIN_TRANSPOSE_PROJECT),
@ -71,8 +71,8 @@ public class LogicalJoinSemiJoinTransposeProject implements ExplorationRuleFacto
GroupPlan c = bottomJoin.right();
// Discard this project, because it is useless.
Plan newBottomJoin = topJoin.withChildren(a, b);
Plan newTopJoin = bottomJoin.withChildren(newBottomJoin, c);
Plan newBottomJoin = topJoin.withChildrenNoContext(a, b);
Plan newTopJoin = bottomJoin.withChildrenNoContext(newBottomJoin, c);
return JoinReorderUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()),
newTopJoin);
}).toRule(RuleType.LOGICAL_JOIN_LOGICAL_SEMI_JOIN_TRANSPOSE_PROJECT)

View File

@ -70,9 +70,9 @@ public class OuterJoinAssoc extends OneExplorationRuleFactory {
* But because we have added eliminate_outer_rule, we don't need to consider this.
*/
LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(b, c);
LogicalJoin newBottomJoin = topJoin.withChildrenNoContext(b, c);
newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext());
LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(a, newBottomJoin);
LogicalJoin newTopJoin = bottomJoin.withChildrenNoContext(a, newBottomJoin);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
setReorderContext(newTopJoin, newBottomJoin);
return newTopJoin;

View File

@ -96,13 +96,13 @@ public class OuterJoinAssocProject extends OneExplorationRuleFactory {
bProjects.addAll(OuterJoinLAsscomProject.forceToNullable(c.getOutputSet()));
/* ********** new Plan ********** */
LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(b, c);
LogicalJoin newBottomJoin = topJoin.withChildrenNoContext(b, c);
newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext());
Plan left = JoinReorderUtils.projectOrSelf(aProjects, a);
Plan right = JoinReorderUtils.projectOrSelf(bProjects, newBottomJoin);
LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(left, right);
LogicalJoin newTopJoin = bottomJoin.withChildrenNoContext(left, right);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
OuterJoinAssoc.setReorderContext(newTopJoin, newBottomJoin);

View File

@ -71,12 +71,12 @@ public class OuterJoinLAsscom extends OneExplorationRuleFactory {
GroupPlan b = bottomJoin.right();
GroupPlan c = topJoin.right();
LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(a, c);
LogicalJoin newBottomJoin = topJoin.withChildrenNoContext(a, c);
newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext());
newBottomJoin.getJoinReorderContext().setHasLAsscom(false);
newBottomJoin.getJoinReorderContext().setHasCommute(false);
LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(newBottomJoin, b);
LogicalJoin newTopJoin = bottomJoin.withChildrenNoContext(newBottomJoin, b);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
newTopJoin.getJoinReorderContext().setHasLAsscom(true);

View File

@ -99,7 +99,7 @@ public class OuterJoinLAsscomProject extends OneExplorationRuleFactory {
aProjects.addAll(forceToNullable(c.getOutputSet()));
/* ********** new Plan ********** */
LogicalJoin newBottomJoin = (LogicalJoin) topJoin.withChildren(a, c);
LogicalJoin newBottomJoin = topJoin.withChildrenNoContext(a, c);
newBottomJoin.getJoinReorderContext().copyFrom(bottomJoin.getJoinReorderContext());
newBottomJoin.getJoinReorderContext().setHasLAsscom(false);
newBottomJoin.getJoinReorderContext().setHasCommute(false);
@ -107,7 +107,7 @@ public class OuterJoinLAsscomProject extends OneExplorationRuleFactory {
Plan left = JoinReorderUtils.projectOrSelf(aProjects, newBottomJoin);
Plan right = JoinReorderUtils.projectOrSelf(bProjects, b);
LogicalJoin newTopJoin = (LogicalJoin) bottomJoin.withChildren(left, right);
LogicalJoin newTopJoin = bottomJoin.withChildrenNoContext(left, right);
newTopJoin.getJoinReorderContext().copyFrom(topJoin.getJoinReorderContext());
newTopJoin.getJoinReorderContext().setHasLAsscom(true);

View File

@ -93,7 +93,7 @@ public class PushdownProjectThroughInnerJoin extends OneExplorationRuleFactory {
Plan newLeft = JoinReorderUtils.projectOrSelf(newAProject.build(), join.left());
if (!rightContains) {
Plan newJoin = join.withChildren(newLeft, join.right());
Plan newJoin = join.withChildrenNoContext(newLeft, join.right());
return JoinReorderUtils.projectOrSelf(new ArrayList<>(project.getOutput()), newJoin);
}
@ -103,7 +103,7 @@ public class PushdownProjectThroughInnerJoin extends OneExplorationRuleFactory {
bConditionSlots.stream().filter(slot -> !bProjectSlots.contains(slot)).forEach(newBProject::add);
Plan newRight = JoinReorderUtils.projectOrSelf(newBProject.build(), join.right());
Plan newJoin = join.withChildren(newLeft, newRight);
Plan newJoin = join.withChildrenNoContext(newLeft, newRight);
return JoinReorderUtils.projectOrSelfInOrder(new ArrayList<>(project.getOutput()), newJoin);
}).toRule(RuleType.PUSH_DOWN_PROJECT_THROUGH_INNER_JOIN);
}

View File

@ -63,7 +63,7 @@ public class PushdownProjectThroughSemiJoin extends OneExplorationRuleFactory {
conditionLeftSlots.stream().filter(slot -> !projectUsedSlots.contains(slot)).forEach(newProject::add);
Plan newLeft = JoinReorderUtils.projectOrSelf(newProject, join.left());
Plan newJoin = join.withChildren(newLeft, join.right());
Plan newJoin = join.withChildrenNoContext(newLeft, join.right());
return JoinReorderUtils.projectOrSelfInOrder(new ArrayList<>(project.getOutput()), newJoin);
}).toRule(RuleType.PUSH_DOWN_PROJECT_THROUGH_SEMI_JOIN);
}

View File

@ -70,8 +70,8 @@ public class SemiJoinSemiJoinTranspose extends OneExplorationRuleFactory {
GroupPlan b = bottomJoin.right();
GroupPlan c = topJoin.right();
Plan newBottomJoin = topJoin.withChildren(a, c);
Plan newTopJoin = bottomJoin.withChildren(newBottomJoin, b);
Plan newBottomJoin = topJoin.withChildrenNoContext(a, c);
Plan newTopJoin = bottomJoin.withChildrenNoContext(newBottomJoin, b);
return newTopJoin;
}).toRule(RuleType.LOGICAL_SEMI_JOIN_SEMI_JOIN_TRANSPOSE);
}

View File

@ -71,13 +71,13 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory
acProjects.add(slot);
}
});
LogicalJoin newBottomSemi = (LogicalJoin) topSemi.withChildren(a, c);
LogicalJoin newBottomSemi = topSemi.withChildrenNoContext(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 = (LogicalJoin) bottomSemi.withChildren(acProject, b);
LogicalJoin newTopSemi = bottomSemi.withChildrenNoContext(acProject, b);
newTopSemi.getJoinReorderContext().copyFrom(topSemi.getJoinReorderContext());
newTopSemi.getJoinReorderContext().setHasLAsscom(true);
return JoinReorderUtils.projectOrSelf(new ArrayList<>(topSemi.getOutput()), newTopSemi);

View File

@ -98,9 +98,9 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
*/
private LogicalJoin(JoinType joinType, List<Expression> hashJoinConjuncts, List<Expression> otherJoinConjuncts,
JoinHint hint, Optional<MarkJoinSlotReference> markJoinSlotReference,
LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild,
JoinReorderContext joinReorderContext) {
super(PlanType.LOGICAL_JOIN, Optional.empty(), Optional.empty(), leftChild, rightChild);
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties,
LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild, JoinReorderContext joinReorderContext) {
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);
@ -168,10 +168,10 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
@Override
public List<Slot> computeOutput() {
return ImmutableList.<Slot>builder()
.addAll(JoinUtils.getJoinOutput(joinType, left(), right()))
.addAll(isMarkJoin()
.addAll(JoinUtils.getJoinOutput(joinType, left(), right()))
.addAll(isMarkJoin()
? ImmutableList.of(markJoinSlotReference.get()) : ImmutableList.of())
.build();
.build();
}
@Override
@ -242,74 +242,63 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
@Override
public LogicalJoin<Plan, Plan> withChildren(List<Plan> children) {
Preconditions.checkArgument(children.size() == 2);
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, children.get(0),
children.get(1), joinReorderContext);
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, markJoinSlotReference,
Optional.empty(), Optional.empty(), children.get(0), children.get(1), joinReorderContext);
}
@Override
public LogicalJoin<Plan, Plan> withGroupExpression(Optional<GroupExpression> groupExpression) {
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference,
groupExpression, Optional.of(getLogicalProperties()), left(), right());
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, markJoinSlotReference,
groupExpression, Optional.of(getLogicalProperties()), left(), right(), joinReorderContext);
}
@Override
public LogicalJoin<Plan, Plan> withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference,
Optional.empty(), logicalProperties, left(), right());
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, markJoinSlotReference,
Optional.empty(), logicalProperties, left(), right(), joinReorderContext);
}
public LogicalJoin withChildrenNoContext(Plan left, Plan right) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, left, right);
}
public LogicalJoin<Plan, Plan> withHashJoinConjuncts(List<Expression> hashJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, this.otherJoinConjuncts, hint, markJoinSlotReference,
left(), right(), joinReorderContext);
left(), right());
}
public LogicalJoin<Plan, Plan> withJoinConjuncts(
List<Expression> hashJoinConjuncts, List<Expression> otherJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts,
hint, markJoinSlotReference, left(), right(), joinReorderContext);
}
public LogicalJoin<Plan, Plan> withHashJoinConjunctsAndChildren(
List<Expression> hashJoinConjuncts, List<Plan> children) {
Preconditions.checkArgument(children.size() == 2);
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, children.get(0),
children.get(1), joinReorderContext);
hint, markJoinSlotReference, left(), right());
}
public LogicalJoin<Plan, Plan> withHashJoinConjunctsAndChildren(
List<Expression> hashJoinConjuncts, Plan left, Plan right) {
Preconditions.checkArgument(children.size() == 2);
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, left, right, joinReorderContext);
markJoinSlotReference, left, right);
}
public LogicalJoin<Plan, Plan> withConjunctsChildren(List<Expression> hashJoinConjuncts,
List<Expression> otherJoinConjuncts, Plan left, Plan right) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, markJoinSlotReference, left,
right, joinReorderContext);
right);
}
public LogicalJoin<Plan, Plan> withJoinType(JoinType joinType) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, left(), right(), joinReorderContext);
markJoinSlotReference, left(), right());
}
public LogicalJoin<Plan, Plan> withTypeChildren(JoinType joinType, Plan left, Plan right) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, left, right, joinReorderContext);
markJoinSlotReference, left, right);
}
public LogicalJoin<Plan, Plan> withOtherJoinConjuncts(List<Expression> otherJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
markJoinSlotReference, left(), right(),
joinReorderContext);
markJoinSlotReference, left(), right());
}
}