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

englefly 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 b25c4975aba [feat](nereids) control the sort phase by session variable 
(#38957)
b25c4975aba is described below

commit b25c4975abad6689d4155f14f4c349818e5d71e7
Author: minghong <[email protected]>
AuthorDate: Wed Aug 7 19:13:17 2024 +0800

    [feat](nereids) control the sort phase by session variable (#38957)
    
    ## Proposed changes
    set sort_phase_num = 1;  enforce one phase sort
    set sort_phase_num = 2; enforce two phase sort
    set sort_phase_num = 0; let cbo decide sort phase
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 .../implementation/LogicalTopNToPhysicalTopN.java  | 28 +++++++++++++++++-----
 .../java/org/apache/doris/qe/SessionVariable.java  |  5 ++++
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalTopNToPhysicalTopN.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalTopNToPhysicalTopN.java
index 6a94fe79cf8..2371407555b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalTopNToPhysicalTopN.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalTopNToPhysicalTopN.java
@@ -23,6 +23,7 @@ import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.SortPhase;
 import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalTopN;
+import org.apache.doris.qe.ConnectContext;
 
 import com.google.common.collect.Lists;
 
@@ -48,11 +49,26 @@ public class LogicalTopNToPhysicalTopN extends 
OneImplementationRuleFactory {
         PhysicalTopN<Plan> localSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(),
                 logicalTopN.getLimit() + logicalTopN.getOffset(), 0, 
SortPhase.LOCAL_SORT,
                 logicalTopN.getLogicalProperties(), logicalTopN.child(0));
-        PhysicalTopN<Plan> twoPhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
-                logicalTopN.getOffset(), SortPhase.MERGE_SORT, 
logicalTopN.getLogicalProperties(), localSort);
-        PhysicalTopN<Plan> onePhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
-                logicalTopN.getOffset(), SortPhase.GATHER_SORT,
-                logicalTopN.getLogicalProperties(), localSort.child(0));
-        return Lists.newArrayList(twoPhaseSort, onePhaseSort);
+        int sortPhaseNum = 0;
+        if (ConnectContext.get() != null) {
+            sortPhaseNum = 
ConnectContext.get().getSessionVariable().sortPhaseNum;
+        }
+        if (sortPhaseNum == 1) {
+            PhysicalTopN<Plan> onePhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
+                    logicalTopN.getOffset(), SortPhase.GATHER_SORT,
+                    logicalTopN.getLogicalProperties(), localSort.child(0));
+            return Lists.newArrayList(onePhaseSort);
+        } else if (sortPhaseNum == 2) {
+            PhysicalTopN<Plan> twoPhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
+                    logicalTopN.getOffset(), SortPhase.MERGE_SORT, 
logicalTopN.getLogicalProperties(), localSort);
+            return Lists.newArrayList(twoPhaseSort);
+        } else {
+            PhysicalTopN<Plan> twoPhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
+                    logicalTopN.getOffset(), SortPhase.MERGE_SORT, 
logicalTopN.getLogicalProperties(), localSort);
+            PhysicalTopN<Plan> onePhaseSort = new 
PhysicalTopN<>(logicalTopN.getOrderKeys(), logicalTopN.getLimit(),
+                    logicalTopN.getOffset(), SortPhase.GATHER_SORT,
+                    logicalTopN.getLogicalProperties(), localSort.child(0));
+            return Lists.newArrayList(twoPhaseSort, onePhaseSort);
+        }
     }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 04c8ba705a4..84507d8edec 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -1100,6 +1100,11 @@ public class SessionVariable implements Serializable, 
Writable {
     @VariableMgr.VarAttr(name = ENABLE_PARALLEL_RESULT_SINK, needForward = 
true, fuzzy = true)
     private boolean enableParallelResultSink = true;
 
+    @VariableMgr.VarAttr(name = "sort_phase_num", fuzzy = true, needForward = 
true,
+            description = 
{"如设置为1,则只生成1阶段sort,设置为2,则只生成2阶段sort,设置其它值,优化器根据代价选择sort类型",
+                    "set the number of sort phases 1 or 2. if set other value, 
let cbo decide the sort type"})
+    public int sortPhaseNum = 0;
+
     @VariableMgr.VarAttr(name = READ_CSV_EMPTY_LINE_AS_NULL, needForward = 
true,
             description = {"在读取csv文件时是否读取csv的空行为null",
                     "Determine whether to read empty rows in CSV files as NULL 
when reading CSV files."})


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to