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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new dbd20f23ae1 [opt](Nereids) forbid one step topn with distribute as 
child (#40066) (#40277)
dbd20f23ae1 is described below

commit dbd20f23ae1d731ebee096b072cf46d40f616cbc
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Mon Sep 2 21:46:38 2024 +0800

    [opt](Nereids) forbid one step topn with distribute as child (#40066) 
(#40277)
    
    pick from master #40066
---
 .../properties/ChildrenPropertiesRegulator.java       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java
index d17d7485cce..a435d09eb80 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/properties/ChildrenPropertiesRegulator.java
@@ -43,6 +43,7 @@ import 
org.apache.doris.nereids.trees.plans.physical.PhysicalNestedLoopJoin;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalSetOperation;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalUnion;
 import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
 import org.apache.doris.nereids.util.JoinUtils;
@@ -468,6 +469,24 @@ public class ChildrenPropertiesRegulator extends 
PlanVisitor<Boolean, Void> {
         return true;
     }
 
+    @Override
+    public Boolean visitPhysicalTopN(PhysicalTopN<? extends Plan> topN, Void 
context) {
+        // process must shuffle
+        visit(topN, context);
+
+        // If child is DistributionSpecGather, topN should forbid two-phase 
topN
+        if (topN.getSortPhase() == SortPhase.LOCAL_SORT
+                && 
childrenProperties.get(0).getDistributionSpec().equals(DistributionSpecGather.INSTANCE))
 {
+            return false;
+        }
+        // forbid one step topn with distribute as child
+        if (topN.getSortPhase() == SortPhase.GATHER_SORT
+                && children.get(0).getPlan() instanceof PhysicalDistribute) {
+            return false;
+        }
+        return true;
+    }
+
     /**
      * check both side real output hash key order are same or not.
      *


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

Reply via email to