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 2021/11/13 09:10:52 UTC

[incubator-doris] branch master updated: [JoinReorder] Add session variable to close join order (#7076)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 11cca0b  [JoinReorder] Add session variable to close join order (#7076)
11cca0b is described below

commit 11cca0b15d54eee8a904de01fd1fb44fcd0d0fdd
Author: EmmyMiao87 <52...@qq.com>
AuthorDate: Sat Nov 13 17:10:44 2021 +0800

    [JoinReorder] Add session variable to close join order (#7076)
    
    The new session variable 'close_join_reorder' is used to turn off all automatic join reorder algorithms.
    If close_join_reorder is true, the Doris will execute query by the order in the original query.
---
 docs/en/administrator-guide/variables.md                    |  4 ++++
 docs/zh-CN/administrator-guide/variables.md                 |  4 ++++
 .../src/main/java/org/apache/doris/analysis/Analyzer.java   | 13 ++++++++++++-
 .../src/main/java/org/apache/doris/analysis/FromClause.java |  2 +-
 .../src/main/java/org/apache/doris/analysis/SelectStmt.java |  2 +-
 .../src/main/java/org/apache/doris/qe/SessionVariable.java  | 10 ++++++++++
 6 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/docs/en/administrator-guide/variables.md b/docs/en/administrator-guide/variables.md
index b57be76..e998a3e 100644
--- a/docs/en/administrator-guide/variables.md
+++ b/docs/en/administrator-guide/variables.md
@@ -439,3 +439,7 @@ Translated with www.DeepL.com/Translator (free version)
      This parameter will be overridden by the `cpu_resource_limit` configuration in the user property.
 
      The default is -1, which means no limit.
+
+* `disable_join_reorder`
+
+    Used to turn off all automatic join reorder algorithms in the system. There are two values: true and false.It is closed by default, that is, the automatic join reorder algorithm of the system is adopted. After set to true, the system will close all automatic sorting algorithms, adopt the original SQL table order, and execute join
diff --git a/docs/zh-CN/administrator-guide/variables.md b/docs/zh-CN/administrator-guide/variables.md
index 5c54440..665c606 100644
--- a/docs/zh-CN/administrator-guide/variables.md
+++ b/docs/zh-CN/administrator-guide/variables.md
@@ -432,3 +432,7 @@ SELECT /*+ SET_VAR(query_timeout = 1, enable_partition_cache=true) */ sleep(3);
     该参数会被 user property 中的 `cpu_resource_limit` 配置覆盖。
 
     默认 -1,即不限制。
+
+* `disable_join_reorder`
+
+   用于关闭所有系统自动的 join reorder 算法。取值有两种:true 和 false。默认行况下关闭,也就是采用系统自动的 join reorder 算法。设置为 true 后,系统会关闭所有自动排序的算法,采用 SQL 原始的表顺序,执行 join
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
index 1424617..c0a93fe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
@@ -1643,6 +1643,17 @@ public class Analyzer {
         this.changeResSmap = changeResSmap;
     }
 
+    // The star join reorder is turned on
+    // when 'enable_join_reorder_based_cost = false' and 'disable_join_reorder = false'
+    public boolean enableStarJoinReorder() {
+        if (globalState.context == null) {
+            return false;
+        }
+        return !globalState.context.getSessionVariable().isEnableJoinReorderBasedCost() && !globalState.context.getSessionVariable().isDisableJoinReorder();
+    }
+
+    // The cost based join reorder is turned on
+    // when 'enable_join_reorder_based_cost = true' and 'disable_join_reorder = false'
     // Load plan and query plan are the same framework
     // Some Load method in doris access through http protocol, which will cause the session may be empty.
     // In order to avoid the occurrence of null pointer exceptions, a check will be added here
@@ -1650,7 +1661,7 @@ public class Analyzer {
         if (globalState.context == null) {
             return false;
         }
-        return globalState.context.getSessionVariable().isEnableJoinReorderBasedCost();
+        return globalState.context.getSessionVariable().isEnableJoinReorderBasedCost() && !globalState.context.getSessionVariable().isDisableJoinReorder();
     }
     
     public boolean safeIsEnableFoldConstantByBe() {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FromClause.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FromClause.java
index 83fab79..c3f953c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FromClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FromClause.java
@@ -129,7 +129,7 @@ public class FromClause implements ParseNode, Iterable<TableRef> {
         // This change will cause the predicate in on clause be adjusted to the front of the association table,
         // causing semantic analysis to fail. Unknown column 'column1' in 'table1'
         // So we need to readjust the order of the tables here.
-        if (!analyzer.safeIsEnableJoinReorderBasedCost()) {
+        if (analyzer.enableStarJoinReorder()) {
             sortTableRefKeepSequenceOfOnClause();
         }
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 335979a..cf5c77e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -520,7 +520,7 @@ public class SelectStmt extends QueryStmt {
         if (needToSql) {
             sqlString_ = toSql();
         }
-        if (!analyzer.safeIsEnableJoinReorderBasedCost()) {
+        if (analyzer.enableStarJoinReorder()) {
             LOG.debug("use old reorder logical in select stmt");
             reorderTable(analyzer);
         }
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 7f98b7e..be66ad7 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
@@ -148,6 +148,9 @@ public class SessionVariable implements Serializable, Writable {
     // then the coordinator be will use the value of `max_send_batch_parallelism_per_job`
     public static final String SEND_BATCH_PARALLELISM = "send_batch_parallelism";
 
+    // turn off all automatic join reorder algorithms
+    public static final String DISABLE_JOIN_REORDER = "disable_join_reorder";
+
     public static final long DEFAULT_INSERT_VISIBLE_TIMEOUT_MS = 10_000;
 
     public static final String EXTRACT_WIDE_RANGE_EXPR = "extract_wide_range_expr";
@@ -384,6 +387,9 @@ public class SessionVariable implements Serializable, Writable {
     @VariableMgr.VarAttr(name = ENABLE_LATERAL_VIEW, needForward = true)
     public boolean enableLateralView = false;
 
+    @VariableMgr.VarAttr(name = DISABLE_JOIN_REORDER)
+    private boolean disableJoinReorder = false;
+
     public long getMaxExecMemByte() {
         return maxExecMemByte;
     }
@@ -800,6 +806,10 @@ public class SessionVariable implements Serializable, Writable {
         this.enableLateralView = enableLateralView;
     }
 
+    public boolean isDisableJoinReorder() {
+        return disableJoinReorder;
+    }
+
     // Serialize to thrift object
     // used for rest api
     public TQueryOptions toThrift() {

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