[fix][Nereids] fix not correct condition to checkReorder in InnerJoinRightAssociate. (#17799)

This commit is contained in:
Weijie Guo
2023-03-15 11:49:03 +08:00
committed by GitHub
parent 97bf07fe26
commit c8de04f9d7
4 changed files with 84 additions and 10 deletions

View File

@ -111,12 +111,9 @@ public class InnerJoinLeftAssociate extends OneExplorationRuleFactory {
* Check JoinReorderContext.
*/
public static boolean checkReorder(LogicalJoin<GroupPlan, ? extends Plan> topJoin) {
if (topJoin.getJoinReorderContext().hasCommute()
|| topJoin.getJoinReorderContext().hasLeftAssociate()
|| topJoin.getJoinReorderContext().hasRightAssociate()
|| topJoin.getJoinReorderContext().hasExchange()) {
return false;
}
return true;
return !topJoin.getJoinReorderContext().hasCommute()
&& !topJoin.getJoinReorderContext().hasLeftAssociate()
&& !topJoin.getJoinReorderContext().hasRightAssociate()
&& !topJoin.getJoinReorderContext().hasExchange();
}
}

View File

@ -111,7 +111,7 @@ public class InnerJoinRightAssociate extends OneExplorationRuleFactory {
public static boolean checkReorder(LogicalJoin<? extends Plan, GroupPlan> topJoin) {
return !topJoin.getJoinReorderContext().hasCommute()
&& !topJoin.getJoinReorderContext().hasRightAssociate()
&& !topJoin.getJoinReorderContext().hasRightAssociate()
&& !topJoin.getJoinReorderContext().hasLeftAssociate()
&& !topJoin.getJoinReorderContext().hasExchange();
}
}

View File

@ -19,6 +19,7 @@ package org.apache.doris.nereids.rules.exploration.join;
import org.apache.doris.common.Pair;
import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.util.LogicalPlanBuilder;
@ -27,6 +28,7 @@ import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PlanChecker;
import org.apache.doris.nereids.util.PlanConstructor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class InnerJoinLeftAssociateTest implements MemoPatternMatchSupported {
@ -35,7 +37,7 @@ class InnerJoinLeftAssociateTest implements MemoPatternMatchSupported {
private final LogicalOlapScan scan3 = PlanConstructor.newLogicalOlapScan(2, "t3", 0);
@Test
public void testSimple() {
void testSimple() {
/*
* LogicalJoin ( type=INNER_JOIN, hashJoinConjuncts=[(id#4 = id#0)], otherJoinConjuncts=[] )
* |--LogicalOlapScan ( qualified=db.t1, output=[id#4, name#5], candidateIndexIds=[], selectedIndexId=-1, preAgg=ON )
@ -65,4 +67,43 @@ class InnerJoinLeftAssociateTest implements MemoPatternMatchSupported {
)
);
}
@Test
void testCheckReorderFailed() {
JoinReorderContext joinReorderContext = new JoinReorderContext();
joinReorderContext.setHasExchange(true);
test(joinReorderContext);
joinReorderContext.setHasExchange(false);
joinReorderContext.setHasCommute(true);
test(joinReorderContext);
joinReorderContext.setHasCommute(false);
joinReorderContext.setHasLeftAssociate(true);
test(joinReorderContext);
joinReorderContext.setHasLeftAssociate(false);
joinReorderContext.setHasRightAssociate(true);
test(joinReorderContext);
joinReorderContext.setHasRightAssociate(false);
}
void test(JoinReorderContext joinReorderContext) {
LogicalJoin topJoin = (LogicalJoin) new LogicalPlanBuilder(scan1)
.join(
new LogicalPlanBuilder(scan2)
.join(scan3, JoinType.INNER_JOIN, Pair.of(0, 0))
.build(),
JoinType.INNER_JOIN, Pair.of(0, 0)
)
.build();
JoinReorderContext topJoinReorderContext = topJoin.getJoinReorderContext();
topJoinReorderContext.copyFrom(joinReorderContext);
PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin)
.applyExploration(InnerJoinLeftAssociate.INSTANCE.build())
.checkMemo(memo -> Assertions.assertEquals(1, memo.getRoot().getLogicalExpressions().size()));
}
}

View File

@ -19,6 +19,7 @@ package org.apache.doris.nereids.rules.exploration.join;
import org.apache.doris.common.Pair;
import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.util.LogicalPlanBuilder;
@ -27,6 +28,7 @@ import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PlanChecker;
import org.apache.doris.nereids.util.PlanConstructor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class InnerJoinRightAssociateTest implements MemoPatternMatchSupported {
@ -35,7 +37,7 @@ class InnerJoinRightAssociateTest implements MemoPatternMatchSupported {
private final LogicalOlapScan scan3 = PlanConstructor.newLogicalOlapScan(2, "t3", 0);
@Test
public void testSimple() {
void testSimple() {
/*-
* LogicalJoin ( type=INNER_JOIN, hashJoinConjuncts=[(id#2 = id#4)], otherJoinConjuncts=[] )
* |--LogicalJoin ( type=INNER_JOIN, hashJoinConjuncts=[(id#0 = id#2)], otherJoinConjuncts=[] )
@ -62,4 +64,38 @@ class InnerJoinRightAssociateTest implements MemoPatternMatchSupported {
)
);
}
@Test
void testCheckReorderFailed() {
JoinReorderContext joinReorderContext = new JoinReorderContext();
joinReorderContext.setHasExchange(true);
assertApplyFailedWithJoinReorderContext(joinReorderContext);
joinReorderContext.setHasExchange(false);
joinReorderContext.setHasCommute(true);
assertApplyFailedWithJoinReorderContext(joinReorderContext);
joinReorderContext.setHasCommute(false);
joinReorderContext.setHasLeftAssociate(true);
assertApplyFailedWithJoinReorderContext(joinReorderContext);
joinReorderContext.setHasLeftAssociate(false);
joinReorderContext.setHasRightAssociate(true);
assertApplyFailedWithJoinReorderContext(joinReorderContext);
joinReorderContext.setHasRightAssociate(false);
}
void assertApplyFailedWithJoinReorderContext(JoinReorderContext joinReorderContext) {
LogicalJoin topJoin = (LogicalJoin) new LogicalPlanBuilder(scan1)
.join(scan2, JoinType.INNER_JOIN, Pair.of(0, 0))
.join(scan3, JoinType.INNER_JOIN, Pair.of(2, 0))
.build();
JoinReorderContext topJoinReorderContext = topJoin.getJoinReorderContext();
topJoinReorderContext.copyFrom(joinReorderContext);
PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin)
.applyExploration(InnerJoinRightAssociate.INSTANCE.build())
.checkMemo(memo -> Assertions.assertEquals(1, memo.getRoot().getLogicalExpressions().size()));
}
}