[enhance](Nereids): remove rule flag in LogicalJoin (#17452)

This commit is contained in:
jakevin
2023-03-07 13:18:50 +08:00
committed by GitHub
parent b8c9875adb
commit 357d8c1746
3 changed files with 18 additions and 34 deletions

View File

@ -42,8 +42,8 @@ public class InferJoinNotNull extends OneRewriteRuleFactory {
@Override
public Rule build() {
// TODO: maybe consider ANTI?
return logicalJoin().when(join -> join.getJoinType().isInnerJoin() || join.getJoinType().isSemiJoin())
.whenNot(LogicalJoin::isGenerateIsNotNull)
return logicalJoin(any(), any())
.when(join -> join.getJoinType().isInnerJoin() || join.getJoinType().isSemiJoin())
.thenApply(ctx -> {
LogicalJoin<Plan, Plan> join = ctx.root;
Set<Expression> conjuncts = new HashSet<>();
@ -69,10 +69,10 @@ public class InferJoinNotNull extends OneRewriteRuleFactory {
right = PlanUtils.filterOrSelf(rightNotNull, join.right());
}
if (left == join.left() && right == join.right()) {
if (left.equals(join.left()) && right.equals(join.right())) {
return null;
}
return join.withIsGenerateIsNotNullAndChildren(true, left, right);
return join.withChildren(left, right);
}).toRule(RuleType.INFER_JOIN_NOT_NULL);
}
}

View File

@ -58,23 +58,21 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
// Use for top-to-down join reorder
private final JoinReorderContext joinReorderContext = new JoinReorderContext();
private final boolean isGenerateIsNotNull;
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, false);
Optional.empty(), Optional.empty(), leftChild, rightChild);
}
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, false);
Optional.empty(), leftChild, rightChild);
}
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, false);
rightChild);
}
/**
@ -82,13 +80,12 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
*/
private LogicalJoin(JoinType joinType, List<Expression> hashJoinConjuncts, List<Expression> otherJoinConjuncts,
JoinHint hint, LEFT_CHILD_TYPE leftChild, RIGHT_CHILD_TYPE rightChild,
JoinReorderContext joinReorderContext, boolean isGenerateIsNotNull) {
JoinReorderContext joinReorderContext) {
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);
}
@ -100,14 +97,12 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties,
LEFT_CHILD_TYPE leftChild,
RIGHT_CHILD_TYPE rightChild,
boolean isGenerateIsNotNull) {
RIGHT_CHILD_TYPE rightChild) {
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.isGenerateIsNotNull = isGenerateIsNotNull;
}
public List<Expression> getOtherJoinConjuncts() {
@ -136,10 +131,6 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
return hint;
}
public boolean isGenerateIsNotNull() {
return isGenerateIsNotNull;
}
public JoinReorderContext getJoinReorderContext() {
return joinReorderContext;
}
@ -212,13 +203,13 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
public LogicalJoin<Plan, Plan> withChildren(List<Plan> children) {
Preconditions.checkArgument(children.size() == 2);
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, children.get(0),
children.get(1), joinReorderContext, isGenerateIsNotNull);
children.get(1), joinReorderContext);
}
@Override
public LogicalJoin<Plan, Plan> withGroupExpression(Optional<GroupExpression> groupExpression) {
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
groupExpression, Optional.of(getLogicalProperties()), left(), right(), isGenerateIsNotNull);
groupExpression, Optional.of(getLogicalProperties()), left(), right());
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
}
@ -226,48 +217,42 @@ public class LogicalJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends
@Override
public LogicalJoin<Plan, Plan> withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
LogicalJoin<Plan, Plan> newJoin = new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint,
Optional.empty(), logicalProperties, left(), right(), isGenerateIsNotNull);
Optional.empty(), logicalProperties, left(), right());
newJoin.getJoinReorderContext().copyFrom(this.getJoinReorderContext());
return newJoin;
}
public LogicalJoin<Plan, Plan> withHashJoinConjuncts(List<Expression> hashJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, this.otherJoinConjuncts, hint, left(), right(),
joinReorderContext, isGenerateIsNotNull);
joinReorderContext);
}
public LogicalJoin<Plan, Plan> withJoinConjuncts(
List<Expression> hashJoinConjuncts, List<Expression> otherJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts,
hint, left(), right(), joinReorderContext, isGenerateIsNotNull);
hint, 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, children.get(0),
children.get(1), joinReorderContext, isGenerateIsNotNull);
children.get(1), joinReorderContext);
}
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);
right, joinReorderContext);
}
public LogicalJoin<Plan, Plan> withJoinType(JoinType joinType) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left(), right(),
joinReorderContext, isGenerateIsNotNull);
joinReorderContext);
}
public LogicalJoin<Plan, Plan> withOtherJoinConjuncts(List<Expression> otherJoinConjuncts) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left(), right(),
joinReorderContext, isGenerateIsNotNull);
}
public LogicalJoin<Plan, Plan> withIsGenerateIsNotNullAndChildren(boolean isGenerateIsNotNull,
Plan left, Plan right) {
return new LogicalJoin<>(joinType, hashJoinConjuncts, otherJoinConjuncts, hint, left,
right, joinReorderContext, isGenerateIsNotNull);
joinReorderContext);
}
}

View File

@ -32,7 +32,6 @@ import org.junit.jupiter.api.Test;
class InferJoinNotNullTest implements MemoPatternMatchSupported {
private final LogicalOlapScan scan1 = PlanConstructor.newLogicalOlapScan(0, "t1", 0);
private final LogicalOlapScan scan2 = PlanConstructor.newLogicalOlapScan(1, "t2", 0);
private final LogicalOlapScan scan3 = PlanConstructor.newLogicalOlapScan(2, "t3", 0);
@Test
void testInferIsNotNull() {