You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/19 13:34:39 UTC

[doris] 13/36: [fix](Nereids): fix sum func in eager agg (#18675)

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

morningman pushed a commit to branch branch-2.0-alpha
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 2c67b8de3420a6993b8321cb4218afe1d0be5cea
Author: jakevin <ja...@gmail.com>
AuthorDate: Mon Apr 17 15:06:28 2023 +0800

    [fix](Nereids): fix sum func in eager agg (#18675)
---
 .../doris/nereids/rules/exploration/CBOUtils.java  | 12 -------
 .../nereids/rules/exploration/EagerCount.java      | 10 +++---
 .../nereids/rules/exploration/EagerGroupBy.java    |  2 +-
 .../rules/exploration/EagerGroupByCount.java       |  8 ++---
 .../nereids/rules/exploration/EagerSplit.java      | 18 +++++-----
 .../exploration/join/InnerJoinLAsscomProject.java  |  2 +-
 .../join/InnerJoinLeftAssociateProject.java        |  2 +-
 .../join/InnerJoinRightAssociateProject.java       |  2 +-
 .../exploration/join/JoinExchangeBothProject.java  |  3 +-
 .../exploration/join/JoinExchangeLeftProject.java  |  2 +-
 .../exploration/join/JoinExchangeRightProject.java |  2 +-
 .../join/LogicalJoinSemiJoinTransposeProject.java  |  4 +--
 .../exploration/join/OuterJoinAssocProject.java    |  2 +-
 .../exploration/join/OuterJoinLAsscomProject.java  |  2 +-
 .../join/PushdownProjectThroughInnerJoin.java      |  5 +--
 .../join/PushdownProjectThroughSemiJoin.java       |  5 +--
 .../join/SemiJoinSemiJoinTransposeProject.java     |  2 +-
 .../trees/plans/logical/LogicalProject.java        |  4 +++
 .../nereids/rules/exploration/EagerCountTest.java  |  9 ++---
 .../rules/exploration/EagerGroupByCountTest.java   |  8 ++---
 .../nereids/rules/exploration/EagerSplitTest.java  | 12 +++----
 .../join/InnerJoinLAsscomProjectTest.java          | 16 +++++----
 .../join/JoinExchangeBothProjectTest.java          | 24 +++++++-------
 .../join/JoinExchangeLeftProjectTest.java          | 16 +++++----
 .../join/JoinExchangeRightProjectTest.java         | 24 ++++++++------
 .../join/OuterJoinLAsscomProjectTest.java          | 38 ++++++++++++----------
 26 files changed, 120 insertions(+), 114 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/CBOUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/CBOUtils.java
index 4ab61cfbee..82c6ef309c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/CBOUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/CBOUtils.java
@@ -35,10 +35,6 @@ import java.util.stream.Collectors;
  * Common
  */
 public class CBOUtils {
-    public static boolean isAllSlotProject(LogicalProject<? extends Plan> project) {
-        return project.getProjects().stream().allMatch(expr -> expr instanceof Slot);
-    }
-
     /**
      * Split project according to whether namedExpr contains by splitChildExprIds.
      * Notice: projects must all be Slot.
@@ -56,14 +52,6 @@ public class CBOUtils {
      * If projects is empty or project output equal plan output, return the original plan.
      */
     public static Plan projectOrSelf(List<NamedExpression> projects, Plan plan) {
-        Set<Slot> outputSet = plan.getOutputSet();
-        if (projects.isEmpty() || (outputSet.size() == projects.size() && outputSet.containsAll(projects))) {
-            return plan;
-        }
-        return new LogicalProject<>(projects, plan);
-    }
-
-    public static Plan projectOrSelfInOrder(List<NamedExpression> projects, Plan plan) {
         if (projects.isEmpty() || projects.equals(plan.getOutput())) {
             return plan;
         }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerCount.java
index 09f0f79a9a..50d19bac1e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerCount.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerCount.java
@@ -26,7 +26,6 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
-import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
@@ -50,7 +49,7 @@ import java.util.Set;
  * |    *
  * (x)
  * ->
- * aggregate: SUM(x) * cnt
+ * aggregate: SUM(x * cnt)
  * |
  * join
  * |   \
@@ -73,7 +72,7 @@ public class EagerCount implements ExplorationRuleFactory {
                         .then(agg -> eagerCount(agg, agg.child(), ImmutableList.of()))
                         .toRule(RuleType.EAGER_COUNT),
                 logicalAggregate(logicalProject(innerLogicalJoin()))
-                        .when(agg -> CBOUtils.isAllSlotProject(agg.child()))
+                        .when(agg -> agg.child().isAllSlots())
                         .when(agg -> agg.child().child().getOtherJoinConjuncts().size() == 0)
                         .when(agg -> agg.getGroupByExpressions().stream().allMatch(e -> e instanceof Slot))
                         .when(agg -> agg.getAggregateFunctions().stream()
@@ -98,7 +97,7 @@ public class EagerCount implements ExplorationRuleFactory {
                 cntAggGroupBy.add(slot);
             }
         }));
-        Alias cnt = new Alias(new Count(Literal.of(1)), "cnt");
+        Alias cnt = new Alias(new Count(), "cnt");
         List<NamedExpression> cntAggOutput = ImmutableList.<NamedExpression>builder()
                 .addAll(cntAggGroupBy).add(cnt).build();
         LogicalAggregate<GroupPlan> cntAgg = new LogicalAggregate<>(
@@ -116,7 +115,8 @@ public class EagerCount implements ExplorationRuleFactory {
         }
         for (Alias oldSum : sumOutputExprs) {
             Sum oldSumFunc = (Sum) oldSum.child();
-            newOutputExprs.add(new Alias(oldSum.getExprId(), new Multiply(oldSumFunc, cnt.toSlot()),
+            Slot slot = (Slot) oldSumFunc.child();
+            newOutputExprs.add(new Alias(oldSum.getExprId(), new Sum(new Multiply(slot, cnt.toSlot())),
                     oldSum.getName()));
         }
         Plan child = PlanUtils.projectOrSelf(projects, newJoin);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupBy.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupBy.java
index 22e7d5194e..4dcce3d0e9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupBy.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupBy.java
@@ -72,7 +72,7 @@ public class EagerGroupBy implements ExplorationRuleFactory {
                         .then(agg -> eagerGroupBy(agg, agg.child(), ImmutableList.of()))
                         .toRule(RuleType.EAGER_GROUP_BY),
                 logicalAggregate(logicalProject(innerLogicalJoin()))
-                        .when(agg -> CBOUtils.isAllSlotProject(agg.child()))
+                        .when(agg -> agg.child().isAllSlots())
                         .when(agg -> agg.child().child().getOtherJoinConjuncts().size() == 0)
                         .when(agg -> agg.getGroupByExpressions().stream().allMatch(e -> e instanceof Slot))
                         .when(agg -> agg.getAggregateFunctions().stream()
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCount.java
index c538250538..582e84f6b5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCount.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCount.java
@@ -26,7 +26,6 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
-import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
@@ -49,7 +48,7 @@ import java.util.Set;
  * |   (y)
  * (x)
  * ->
- * aggregate: SUM(sum1), SUM(y) * cnt
+ * aggregate: SUM(sum1), SUM(y  * cnt)
  * |
  * join
  * |   \
@@ -96,7 +95,7 @@ public class EagerGroupByCount extends OneExplorationRuleFactory {
                     for (int i = 0; i < leftSums.size(); i++) {
                         bottomSums.add(new Alias(new Sum(leftSums.get(i).child()), "sum" + i));
                     }
-                    Alias cnt = new Alias(new Count(Literal.of(1)), "cnt");
+                    Alias cnt = new Alias(new Count(), "cnt");
                     List<NamedExpression> bottomAggOutput = ImmutableList.<NamedExpression>builder()
                             .addAll(bottomAggGroupBy).addAll(bottomSums).add(cnt).build();
                     LogicalAggregate<GroupPlan> bottomAgg = new LogicalAggregate<>(
@@ -129,7 +128,8 @@ public class EagerGroupByCount extends OneExplorationRuleFactory {
                     }
                     for (Alias oldSum : rightSumOutputExprs) {
                         Sum oldSumFunc = (Sum) oldSum.child();
-                        newOutputExprs.add(new Alias(oldSum.getExprId(), new Multiply(oldSumFunc, cnt.toSlot()),
+                        Slot slot = (Slot) oldSumFunc.child();
+                        newOutputExprs.add(new Alias(oldSum.getExprId(), new Sum(new Multiply(slot, cnt.toSlot())),
                                 oldSum.getName()));
                     }
                     return agg.withAggOutput(newOutputExprs).withChildren(newJoin);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerSplit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerSplit.java
index abf6dabad8..89023ca69f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerSplit.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/EagerSplit.java
@@ -27,7 +27,6 @@ import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
-import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
@@ -51,7 +50,7 @@ import java.util.Set;
  * |   (y)
  * (x)
  * ->
- * aggregate: SUM(sum1) * cnt2, SUM(sum2) * cnt1
+ * aggregate: SUM(sum1 * cnt2), SUM(sum2 * cnt1)
  * |
  * join
  * |   \
@@ -98,7 +97,7 @@ public class EagerSplit extends OneExplorationRuleFactory {
                     for (int i = 0; i < leftSums.size(); i++) {
                         leftBottomSums.add(new Alias(new Sum(leftSums.get(i).child()), "left_sum" + i));
                     }
-                    Alias leftCnt = new Alias(new Count(Literal.of(1)), "left_cnt");
+                    Alias leftCnt = new Alias(new Count(), "left_cnt");
                     List<NamedExpression> leftBottomAggOutput = ImmutableList.<NamedExpression>builder()
                             .addAll(leftBottomAggGroupBy).addAll(leftBottomSums).add(leftCnt).build();
                     LogicalAggregate<GroupPlan> leftBottomAgg = new LogicalAggregate<>(
@@ -117,7 +116,7 @@ public class EagerSplit extends OneExplorationRuleFactory {
                     for (int i = 0; i < rightSums.size(); i++) {
                         rightBottomSums.add(new Alias(new Sum(rightSums.get(i).child()), "right_sum" + i));
                     }
-                    Alias rightCnt = new Alias(new Count(Literal.of(1)), "right_cnt");
+                    Alias rightCnt = new Alias(new Count(), "right_cnt");
                     List<NamedExpression> rightBottomAggOutput = ImmutableList.<NamedExpression>builder()
                             .addAll(rightBottomAggGroupBy).addAll(rightBottomSums).add(rightCnt).build();
                     LogicalAggregate<GroupPlan> rightBottomAgg = new LogicalAggregate<>(
@@ -146,16 +145,15 @@ public class EagerSplit extends OneExplorationRuleFactory {
                     Preconditions.checkState(rightSumOutputExprs.size() == rightBottomSums.size());
                     for (int i = 0; i < leftSumOutputExprs.size(); i++) {
                         Alias oldSum = leftSumOutputExprs.get(i);
-                        Slot bottomSum = leftBottomSums.get(i).toSlot();
-                        Alias newSum = new Alias(oldSum.getExprId(),
-                                new Multiply(new Sum(bottomSum), rightCnt.toSlot()), oldSum.getName());
-                        newOutputExprs.add(newSum);
+                        Slot slot = leftBottomSums.get(i).toSlot();
+                        newOutputExprs.add(new Alias(oldSum.getExprId(), new Sum(new Multiply(slot, rightCnt.toSlot())),
+                                oldSum.getName()));
                     }
                     for (int i = 0; i < rightSumOutputExprs.size(); i++) {
                         Alias oldSum = rightSumOutputExprs.get(i);
                         Slot bottomSum = rightBottomSums.get(i).toSlot();
-                        Alias newSum = new Alias(oldSum.getExprId(),
-                                new Multiply(new Sum(bottomSum), leftCnt.toSlot()), oldSum.getName());
+                        Alias newSum = new Alias(oldSum.getExprId(), new Sum(new Multiply(bottomSum, leftCnt.toSlot())),
+                                oldSum.getName());
                         newOutputExprs.add(newSum);
                     }
                     return agg.withAggOutput(newOutputExprs).withChildren(newJoin);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
index 4c6147ae00..3304278ab1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
@@ -56,7 +56,7 @@ public class InnerJoinLAsscomProject extends OneExplorationRuleFactory {
                 .when(topJoin -> InnerJoinLAsscom.checkReorder(topJoin, topJoin.left().child()))
                 .whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .then(topJoin -> {
                     /* ********** init ********** */
                     LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.left().child();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociateProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociateProject.java
index 4dd425d0ab..12bb8bb530 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociateProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLeftAssociateProject.java
@@ -52,7 +52,7 @@ public class InnerJoinLeftAssociateProject extends OneExplorationRuleFactory {
                 .when(InnerJoinLeftAssociate::checkReorder)
                 .whenNot(join -> join.hasJoinHint() || join.right().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.right().child().isMarkJoin())
-                .when(join -> CBOUtils.isAllSlotProject(join.right()))
+                .when(join -> join.right().isAllSlots())
                 .then(topJoin -> {
                     LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.right().child();
                     GroupPlan a = topJoin.left();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociateProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociateProject.java
index cfc4364a38..77183ed4f7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociateProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinRightAssociateProject.java
@@ -50,7 +50,7 @@ public class InnerJoinRightAssociateProject extends OneExplorationRuleFactory {
                 .when(InnerJoinRightAssociate::checkReorder)
                 .whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .then(topJoin -> {
                     LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.left().child();
                     GroupPlan a = bottomJoin.left();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProject.java
index 0543fcefb7..87d352237c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProject.java
@@ -54,8 +54,7 @@ public class JoinExchangeBothProject extends OneExplorationRuleFactory {
     public Rule build() {
         return innerLogicalJoin(logicalProject(innerLogicalJoin()), logicalProject(innerLogicalJoin()))
             .when(JoinExchange::checkReorder)
-            .when(join -> CBOUtils.isAllSlotProject(join.left())
-                    && CBOUtils.isAllSlotProject(join.right()))
+            .when(join -> join.left().isAllSlots() && join.right().isAllSlots())
             .whenNot(join -> join.hasJoinHint()
                     || join.left().child().hasJoinHint() || join.right().child().hasJoinHint())
             .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin() || join.right().child().isMarkJoin())
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProject.java
index 9f8013f1d8..3d54f5731c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProject.java
@@ -54,7 +54,7 @@ public class JoinExchangeLeftProject extends OneExplorationRuleFactory {
     public Rule build() {
         return innerLogicalJoin(logicalProject(innerLogicalJoin()), innerLogicalJoin())
                 .when(JoinExchange::checkReorder)
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .whenNot(join -> join.hasJoinHint()
                         || join.left().child().hasJoinHint() || join.right().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin() || join.right().isMarkJoin())
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
index f5df8917c4..6403c48efe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProject.java
@@ -54,7 +54,7 @@ public class JoinExchangeRightProject extends OneExplorationRuleFactory {
     public Rule build() {
         return innerLogicalJoin(innerLogicalJoin(), logicalProject(innerLogicalJoin()))
                 .when(JoinExchange::checkReorder)
-                .when(join -> CBOUtils.isAllSlotProject(join.right()))
+                .when(join -> join.right().isAllSlots())
                 .whenNot(join -> join.hasJoinHint()
                         || join.left().hasJoinHint() || join.right().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().isMarkJoin() || join.right().child().isMarkJoin())
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 bcb66436b5..30c6e4b1ee 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
@@ -46,7 +46,7 @@ public class LogicalJoinSemiJoinTransposeProject implements ExplorationRuleFacto
                                 || topJoin.getJoinType().isLeftOuterJoin())))
                         .whenNot(topJoin -> topJoin.hasJoinHint() || topJoin.left().child().hasJoinHint())
                         .whenNot(LogicalJoin::isMarkJoin)
-                        .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                        .when(join -> join.left().isAllSlots())
                         .then(topJoin -> {
                             LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.left().child();
                             GroupPlan a = bottomJoin.left();
@@ -64,7 +64,7 @@ public class LogicalJoinSemiJoinTransposeProject implements ExplorationRuleFacto
                         .when(topJoin -> (topJoin.right().child().getJoinType().isLeftSemiOrAntiJoin()
                                 && (topJoin.getJoinType().isInnerJoin()
                                 || topJoin.getJoinType().isRightOuterJoin())))
-                        .when(join -> CBOUtils.isAllSlotProject(join.right()))
+                        .when(join -> join.right().isAllSlots())
                         .then(topJoin -> {
                             LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.right().child();
                             GroupPlan a = topJoin.left();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java
index 286d03c505..308e1db583 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinAssocProject.java
@@ -59,7 +59,7 @@ public class OuterJoinAssocProject extends OneExplorationRuleFactory {
                 .whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
                 .when(join -> OuterJoinAssoc.checkCondition(join, join.left().child().left().getOutputSet()))
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .then(topJoin -> {
                     /* ********** init ********** */
                     List<NamedExpression> projects = topJoin.left().getProjects();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
index 72d0982edd..2e6007fe54 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
@@ -61,7 +61,7 @@ public class OuterJoinLAsscomProject extends OneExplorationRuleFactory {
                 .when(topJoin -> OuterJoinLAsscom.checkReorder(topJoin, topJoin.left().child()))
                 .whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .then(topJoin -> {
                     /* ********** init ********** */
                     List<NamedExpression> projects = topJoin.left().getProjects();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
index bc1c45f243..6761153e17 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughInnerJoin.java
@@ -27,6 +27,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableList.Builder;
@@ -52,7 +53,7 @@ public class PushdownProjectThroughInnerJoin extends OneExplorationRuleFactory {
     @Override
     public Rule build() {
         return logicalProject(logicalJoin())
-            .whenNot(CBOUtils::isAllSlotProject)
+            .whenNot(LogicalProject::isAllSlots)
             .when(project -> project.child().getJoinType().isInnerJoin())
             .whenNot(project -> project.child().hasJoinHint())
             .then(project -> {
@@ -105,7 +106,7 @@ public class PushdownProjectThroughInnerJoin extends OneExplorationRuleFactory {
                 Plan newRight = CBOUtils.projectOrSelf(newBProject.build(), join.right());
 
                 Plan newJoin = join.withChildrenNoContext(newLeft, newRight);
-                return CBOUtils.projectOrSelfInOrder(new ArrayList<>(project.getOutput()), newJoin);
+                return CBOUtils.projectOrSelf(new ArrayList<>(project.getOutput()), newJoin);
             }).toRule(RuleType.PUSH_DOWN_PROJECT_THROUGH_INNER_JOIN);
     }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
index c248874589..79b2047af0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/PushdownProjectThroughSemiJoin.java
@@ -27,6 +27,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -52,7 +53,7 @@ public class PushdownProjectThroughSemiJoin extends OneExplorationRuleFactory {
         return logicalProject(logicalJoin())
             .when(project -> project.child().getJoinType().isLeftSemiOrAntiJoin())
             // Just pushdown project with non-column expr like (t.id + 1)
-            .whenNot(CBOUtils::isAllSlotProject)
+            .whenNot(LogicalProject::isAllSlots)
             .whenNot(project -> project.child().hasJoinHint())
             .then(project -> {
                 LogicalJoin<GroupPlan, GroupPlan> join = project.child();
@@ -65,7 +66,7 @@ public class PushdownProjectThroughSemiJoin extends OneExplorationRuleFactory {
                 Plan newLeft = CBOUtils.projectOrSelf(newProject, join.left());
 
                 Plan newJoin = join.withChildrenNoContext(newLeft, join.right());
-                return CBOUtils.projectOrSelfInOrder(new ArrayList<>(project.getOutput()), newJoin);
+                return CBOUtils.projectOrSelf(new ArrayList<>(project.getOutput()), newJoin);
             }).toRule(RuleType.PUSH_DOWN_PROJECT_THROUGH_SEMI_JOIN);
     }
 
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 85be57370d..f28f427786 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
@@ -56,7 +56,7 @@ public class SemiJoinSemiJoinTransposeProject extends OneExplorationRuleFactory
                 .when(topSemi -> InnerJoinLAsscom.checkReorder(topSemi, topSemi.left().child()))
                 .whenNot(join -> join.hasJoinHint() || join.left().child().hasJoinHint())
                 .whenNot(join -> join.isMarkJoin() || join.left().child().isMarkJoin())
-                .when(join -> CBOUtils.isAllSlotProject(join.left()))
+                .when(join -> join.left().isAllSlots())
                 .then(topSemi -> {
                     LogicalJoin<GroupPlan, GroupPlan> bottomSemi = topSemi.left().child();
                     LogicalProject abProject = topSemi.left();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalProject.java
index 514fc74340..c13ffa518c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalProject.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalProject.java
@@ -102,6 +102,10 @@ public class LogicalProject<CHILD_TYPE extends Plan> extends LogicalUnary<CHILD_
         return excepts;
     }
 
+    public boolean isAllSlots() {
+        return projects.stream().allMatch(NamedExpression::isSlot);
+    }
+
     @Override
     public List<Slot> computeOutput() {
         return projects.stream()
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerCountTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerCountTest.java
index ca65e4be78..c3ad243966 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerCountTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerCountTest.java
@@ -49,14 +49,15 @@ class EagerCountTest implements MemoPatternMatchSupported {
                 .build();
         PlanChecker.from(MemoTestUtils.createConnectContext(), agg)
                 .applyExploration(new EagerCount().buildRules())
+                .printlnExploration()
                 .matchesExploration(
                     logicalAggregate(
                         logicalJoin(
                           logicalOlapScan(),
-                          logicalAggregate().when(cntAgg -> cntAgg.getOutputExprsSql().equals("sid, count(1) AS `cnt`"))
+                          logicalAggregate().when(cntAgg -> cntAgg.getOutputExprsSql().equals("sid, count(*) AS `cnt`"))
                         )
                     ).when(newAgg -> newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
-                                        && newAgg.getOutputExprsSql().equals("(sum(gender) * cnt) AS `sum`"))
+                                        && newAgg.getOutputExprsSql().equals("sum((gender * cnt)) AS `sum`"))
                 );
     }
 
@@ -78,11 +79,11 @@ class EagerCountTest implements MemoPatternMatchSupported {
                     logicalAggregate(
                         logicalJoin(
                             logicalOlapScan(),
-                            logicalAggregate().when(cntAgg -> cntAgg.getOutputExprsSql().equals("sid, count(1) AS `cnt`"))
+                            logicalAggregate().when(cntAgg -> cntAgg.getOutputExprsSql().equals("sid, count(*) AS `cnt`"))
                         )
                     ).when(newAgg ->
                         newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
-                            && newAgg.getOutputExprsSql().equals("(sum(gender) * cnt) AS `sum0`, (sum(name) * cnt) AS `sum1`, (sum(age) * cnt) AS `sum2`"))
+                            && newAgg.getOutputExprsSql().equals("sum((gender * cnt)) AS `sum0`, sum((name * cnt)) AS `sum1`, sum((age * cnt)) AS `sum2`"))
                 );
     }
 }
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCountTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCountTest.java
index de132d22d2..8115525de1 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCountTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerGroupByCountTest.java
@@ -58,12 +58,12 @@ class EagerGroupByCountTest implements MemoPatternMatchSupported {
                         logicalAggregate(
                                 logicalJoin(
                                         logicalAggregate().when(
-                                                bottomAgg -> bottomAgg.getOutputExprsSql().equals("id, sum(age) AS `sum0`, count(1) AS `cnt`")),
+                                                bottomAgg -> bottomAgg.getOutputExprsSql().equals("id, sum(age) AS `sum0`, count(*) AS `cnt`")),
                                         logicalOlapScan()
                                 )
                         ).when(newAgg ->
                                 newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
-                                        && newAgg.getOutputExprsSql().equals("sum(sum0) AS `lsum0`, (sum(grade) * cnt) AS `rsum0`"))
+                                        && newAgg.getOutputExprsSql().equals("sum(sum0) AS `lsum0`, sum((grade * cnt)) AS `rsum0`"))
                 );
     }
 
@@ -89,13 +89,13 @@ class EagerGroupByCountTest implements MemoPatternMatchSupported {
                         logicalAggregate(
                                 logicalJoin(
                                         logicalAggregate().when(cntAgg -> cntAgg.getOutputExprsSql()
-                                                .equals("id, sum(gender) AS `sum0`, sum(name) AS `sum1`, sum(age) AS `sum2`, count(1) AS `cnt`")),
+                                                .equals("id, sum(gender) AS `sum0`, sum(name) AS `sum1`, sum(age) AS `sum2`, count(*) AS `cnt`")),
                                         logicalOlapScan()
                                 )
                         ).when(newAgg ->
                                 newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
                                         && newAgg.getOutputExprsSql()
-                                        .equals("sum(sum0) AS `lsum0`, sum(sum1) AS `lsum1`, sum(sum2) AS `lsum2`, (sum(cid) * cnt) AS `rsum0`, (sum(grade) * cnt) AS `rsum1`"))
+                                        .equals("sum(sum0) AS `lsum0`, sum(sum1) AS `lsum1`, sum(sum2) AS `lsum2`, sum((cid * cnt)) AS `rsum0`, sum((grade * cnt)) AS `rsum1`"))
                 );
     }
 }
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerSplitTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerSplitTest.java
index 37e347894f..4ffeb923f5 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerSplitTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/EagerSplitTest.java
@@ -58,13 +58,13 @@ class EagerSplitTest implements MemoPatternMatchSupported {
                         logicalAggregate(
                                 logicalJoin(
                                         logicalAggregate().when(
-                                                a -> a.getOutputExprsSql().equals("id, sum(age) AS `left_sum0`, count(1) AS `left_cnt`")),
+                                                a -> a.getOutputExprsSql().equals("id, sum(age) AS `left_sum0`, count(*) AS `left_cnt`")),
                                         logicalAggregate().when(
-                                                a -> a.getOutputExprsSql().equals("sid, sum(grade) AS `right_sum0`, count(1) AS `right_cnt`"))
+                                                a -> a.getOutputExprsSql().equals("sid, sum(grade) AS `right_sum0`, count(*) AS `right_cnt`"))
                                 )
                         ).when(newAgg ->
                                 newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
-                                        && newAgg.getOutputExprsSql().equals("(sum(left_sum0) * right_cnt) AS `lsum0`, (sum(right_sum0) * left_cnt) AS `rsum0`"))
+                                        && newAgg.getOutputExprsSql().equals("sum((left_sum0 * right_cnt)) AS `lsum0`, sum((right_sum0 * left_cnt)) AS `rsum0`"))
                 );
     }
 
@@ -89,14 +89,14 @@ class EagerSplitTest implements MemoPatternMatchSupported {
                         logicalAggregate(
                                 logicalJoin(
                                         logicalAggregate().when(a -> a.getOutputExprsSql()
-                                                .equals("id, sum(gender) AS `left_sum0`, sum(name) AS `left_sum1`, sum(age) AS `left_sum2`, count(1) AS `left_cnt`")),
+                                                .equals("id, sum(gender) AS `left_sum0`, sum(name) AS `left_sum1`, sum(age) AS `left_sum2`, count(*) AS `left_cnt`")),
                                         logicalAggregate().when(a -> a.getOutputExprsSql()
-                                                .equals("sid, sum(cid) AS `right_sum0`, sum(grade) AS `right_sum1`, count(1) AS `right_cnt`"))
+                                                .equals("sid, sum(cid) AS `right_sum0`, sum(grade) AS `right_sum1`, count(*) AS `right_cnt`"))
                                 )
                         ).when(newAgg ->
                                 newAgg.getGroupByExpressions().equals(((Aggregate) agg).getGroupByExpressions())
                                         && newAgg.getOutputExprsSql()
-                                        .equals("(sum(left_sum0) * right_cnt) AS `lsum0`, (sum(left_sum1) * right_cnt) AS `lsum1`, (sum(left_sum2) * right_cnt) AS `lsum2`, (sum(right_sum0) * left_cnt) AS `rsum0`, (sum(right_sum1) * left_cnt) AS `rsum1`"))
+                                        .equals("sum((left_sum0 * right_cnt)) AS `lsum0`, sum((left_sum1 * right_cnt)) AS `lsum1`, sum((left_sum2 * right_cnt)) AS `lsum2`, sum((right_sum0 * left_cnt)) AS `rsum0`, sum((right_sum1 * left_cnt)) AS `rsum1`"))
                 );
     }
 }
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProjectTest.java
index e7c34c1cfb..f1c73f4edf 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProjectTest.java
@@ -78,15 +78,17 @@ class InnerJoinLAsscomProjectTest implements MemoPatternMatchSupported {
                 .applyExploration(InnerJoinLAsscomProject.INSTANCE.build())
                 .printlnExploration()
                 .matchesExploration(
+                    logicalProject(
                         logicalJoin(
-                                logicalJoin(
-                                        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"))
-                                ).when(project -> project.getProjects().size() == 1)
+                            logicalJoin(
+                                    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"))
+                            ).when(project -> project.getProjects().size() == 1)
                         )
+                    )
                 );
     }
 
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProjectTest.java
index 0e7a390c17..d48bbff1c1 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeBothProjectTest.java
@@ -54,17 +54,19 @@ class JoinExchangeBothProjectTest implements MemoPatternMatchSupported {
         PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
                 .applyExploration(JoinExchangeBothProject.INSTANCE.build())
                 .matchesExploration(
-                    logicalJoin(
-                        logicalProject(
-                            logicalJoin(
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
-                            )
-                        ),
-                        logicalProject(
-                            logicalJoin(
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")),
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t4"))
+                    logicalProject(
+                        logicalJoin(
+                            logicalProject(
+                                logicalJoin(
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
+                                )
+                            ),
+                            logicalProject(
+                                logicalJoin(
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")),
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t4"))
+                                )
                             )
                         )
                     )
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProjectTest.java
index 7a1a2998e8..95d9286647 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeLeftProjectTest.java
@@ -54,15 +54,17 @@ class JoinExchangeLeftProjectTest implements MemoPatternMatchSupported {
                 .applyExploration(JoinExchangeLeftProject.INSTANCE.build())
                 .printlnExploration()
                 .matchesExploration(
-                    logicalJoin(
+                    logicalProject(
                         logicalJoin(
-                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
-                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
-                        ),
-                        logicalProject(
                             logicalJoin(
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")),
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t4"))
+                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
+                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
+                            ),
+                            logicalProject(
+                                logicalJoin(
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")),
+                                        logicalOlapScan().when(scan -> scan.getTable().getName().equals("t4"))
+                                )
                             )
                         )
                     )
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProjectTest.java
index 4b8d038624..113facaa5d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/JoinExchangeRightProjectTest.java
@@ -54,18 +54,22 @@ class JoinExchangeRightProjectTest implements MemoPatternMatchSupported {
                 .applyExploration(JoinExchangeRightProject.INSTANCE.build())
                 .printlnExploration()
                 .matchesExploration(
-                    logicalJoin(
-                        logicalJoin(
-                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
-                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
-                        ),
                         logicalProject(
-                            logicalJoin(
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")),
-                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t4"))
-                            )
+                                logicalJoin(
+                                        logicalJoin(
+                                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
+                                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
+                                        ),
+                                        logicalProject(
+                                                logicalJoin(
+                                                        logicalOlapScan().when(
+                                                                scan -> scan.getTable().getName().equals("t2")),
+                                                        logicalOlapScan().when(
+                                                                scan -> scan.getTable().getName().equals("t4"))
+                                                )
+                                        )
+                                )
                         )
-                    )
                 );
     }
 }
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProjectTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProjectTest.java
index c94dcb12ca..9f69966bd9 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProjectTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProjectTest.java
@@ -56,15 +56,17 @@ class OuterJoinLAsscomProjectTest implements MemoPatternMatchSupported {
                 .applyExploration(OuterJoinLAsscomProject.INSTANCE.build())
                 .printlnExploration()
                 .matchesExploration(
+                    logicalProject(
                         logicalJoin(
-                                logicalJoin(
-                                        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"))
-                                ).when(project -> project.getProjects().size() == 1)
+                            logicalJoin(
+                                    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"))
+                            ).when(project -> project.getProjects().size() == 1)
                         )
+                    )
                 );
     }
 
@@ -82,16 +84,18 @@ class OuterJoinLAsscomProjectTest implements MemoPatternMatchSupported {
                 .applyExploration(OuterJoinLAsscomProject.INSTANCE.build())
                 .printlnExploration()
                 .matchesExploration(
-                    logicalJoin(
-                        logicalProject(
-                            logicalJoin(
-                                logicalProject(logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1"))),
-                                logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
-                            )
-                        ).when(project -> project.getProjects().size() == 3), // t1.id Add t3.id, t3.name
-                        logicalProject(
-                            logicalProject(logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")))
-                        ).when(project -> project.getProjects().size() == 1)
+                    logicalProject(
+                        logicalJoin(
+                            logicalProject(
+                                logicalJoin(
+                                    logicalProject(logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1"))),
+                                    logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
+                                )
+                            ).when(project -> project.getProjects().size() == 3), // t1.id Add t3.id, t3.name
+                            logicalProject(
+                                logicalProject(logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")))
+                            ).when(project -> project.getProjects().size() == 1)
+                        )
                     )
                 );
     }


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