This is an automated email from the ASF dual-hosted git repository.

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 46fceed7d7f [fix](nereids)semi join transpose rule produce wrong plan 
if there is mark join (#39152)
46fceed7d7f is described below

commit 46fceed7d7f17c87355af17b76acbb910c20dd36
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Sun Aug 11 10:59:40 2024 +0800

    [fix](nereids)semi join transpose rule produce wrong plan if there is mark 
join (#39152)
---
 .../join/LogicalJoinSemiJoinTransposeProject.java  |  4 ++++
 .../join/SemiJoinSemiJoinTransposeProject.java     |  1 +
 .../LogicalJoinSemiJoinTransposeProjectTest.java   | 24 ++++++++++++++++++++++
 .../join/SemiJoinSemiJoinTransposeProjectTest.java |  6 +++---
 .../doris/nereids/util/LogicalPlanBuilder.java     | 11 ++++++++++
 5 files changed, 43 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProject.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProject.java
index a0e2b83cc1b..0531c6e54ac 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProject.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProject.java
@@ -68,6 +68,8 @@ public class LogicalJoinSemiJoinTransposeProject implements 
ExplorationRuleFacto
                                     .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
                             bottomJoin.getOtherJoinConjuncts()
                                     .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
+                            bottomJoin.getMarkJoinConjuncts()
+                                    .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
                             Plan newBottomJoin = 
topJoin.withChildrenNoContext(a, c, null);
                             Plan left = CBOUtils.newProject(topUsedExprIds, 
newBottomJoin);
                             Plan right = 
CBOUtils.newProjectIfNeeded(topUsedExprIds, b);
@@ -100,6 +102,8 @@ public class LogicalJoinSemiJoinTransposeProject implements 
ExplorationRuleFacto
                                     .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
                             bottomJoin.getOtherJoinConjuncts()
                                     .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
+                            bottomJoin.getMarkJoinConjuncts()
+                                    .forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
                             Plan newBottomJoin = 
topJoin.withChildrenNoContext(a, b, null);
                             Plan left = CBOUtils.newProject(topUsedExprIds, 
newBottomJoin);
                             Plan right = 
CBOUtils.newProjectIfNeeded(topUsedExprIds, c);
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 b4a5b177f8c..359d6e13552 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
@@ -104,6 +104,7 @@ public class SemiJoinSemiJoinTransposeProject extends 
OneExplorationRuleFactory
                     topProject.getProjects().forEach(expr -> 
topUsedExprIds.addAll(expr.getInputSlotExprIds()));
                     bottomSemi.getHashJoinConjuncts().forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
                     bottomSemi.getOtherJoinConjuncts().forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
+                    bottomSemi.getMarkJoinConjuncts().forEach(e -> 
topUsedExprIds.addAll(e.getInputSlotExprIds()));
 
                     Plan left = CBOUtils.newProject(topUsedExprIds, 
newBottomSemi);
                     Plan right = CBOUtils.newProjectIfNeeded(topUsedExprIds, 
b);
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProjectTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProjectTest.java
index 27e162f4af7..70f6de6c320 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProjectTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/LogicalJoinSemiJoinTransposeProjectTest.java
@@ -105,4 +105,28 @@ class LogicalJoinSemiJoinTransposeProjectTest implements 
MemoPatternMatchSupport
                         )
                 );
     }
+
+    @Test
+    public void generateTopProjectMarkJoin() {
+        LogicalPlan topJoin1 = new LogicalPlanBuilder(scan1)
+                .markJoinWithMarkConjuncts(scan2, JoinType.LEFT_SEMI_JOIN, 
Pair.of(0, 0)) // t1.id = t2.id
+                .project(ImmutableList.of(1))
+                .join(scan3, JoinType.INNER_JOIN, Pair.of(0, 0)) // t1.id = 
t3.id
+                .project(ImmutableList.of(0))
+                .build();
+
+        PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin1)
+                
.applyExploration(LogicalJoinSemiJoinTransposeProject.INSTANCE.buildRules())
+                .matchesExploration(
+                        logicalProject(
+                                leftSemiLogicalJoin(
+                                        logicalProject(innerLogicalJoin(
+                                                logicalOlapScan().when(scan -> 
scan.getTable().getName().equals("t1")),
+                                                logicalOlapScan().when(scan -> 
scan.getTable().getName().equals("t3"))
+                                        )),
+                                        
logicalProject(logicalOlapScan().when(scan -> 
scan.getTable().getName().equals("t2")))
+                                )
+                        )
+                );
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
index dd654a2f428..d37be0a1a13 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/SemiJoinSemiJoinTransposeProjectTest.java
@@ -74,10 +74,10 @@ public class SemiJoinSemiJoinTransposeProjectTest 
implements MemoPatternMatchSup
     @Test
     public void testSemiProjectSemiCommuteMarkJoin() {
         LogicalPlan topJoin = new LogicalPlanBuilder(scan1)
-                .markJoin(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0))
+                .markJoinWithMarkConjuncts(scan2, JoinType.LEFT_SEMI_JOIN, 
Pair.of(0, 0))
                 .project(ImmutableList.of(0, 2))
-                .markJoin(scan3, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 1))
-                .projectAll()
+                .markJoinWithMarkConjuncts(scan3, JoinType.LEFT_SEMI_JOIN, 
Pair.of(0, 1))
+                .project(ImmutableList.of(1, 2))
                 .build();
         PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin)
                 
.applyExploration(SemiJoinSemiJoinTransposeProject.INSTANCE.build())
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 ba81fa7e4a3..ccdcd253279 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
@@ -120,6 +120,17 @@ public class LogicalPlanBuilder {
         return from(join);
     }
 
+    public LogicalPlanBuilder markJoinWithMarkConjuncts(LogicalPlan right, 
JoinType joinType, Pair<Integer, Integer> hashOnSlots) {
+        ImmutableList<EqualTo> markConjuncts = ImmutableList.of(
+                new EqualTo(this.plan.getOutput().get(hashOnSlots.first), 
right.getOutput().get(hashOnSlots.second)));
+
+        LogicalJoin<LogicalPlan, LogicalPlan> join = new 
LogicalJoin<>(joinType, Collections.emptyList(),
+                Collections.emptyList(), new ArrayList<>(markConjuncts),
+                new DistributeHint(DistributeType.NONE), Optional.of(new 
MarkJoinSlotReference("fake")),
+                this.plan, right, null);
+        return from(join);
+    }
+
     public LogicalPlanBuilder join(LogicalPlan right, JoinType joinType, 
Pair<Integer, Integer> hashOnSlots) {
         ImmutableList<EqualTo> hashConjuncts = ImmutableList.of(
                 new EqualTo(this.plan.getOutput().get(hashOnSlots.first), 
right.getOutput().get(hashOnSlots.second)));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to