You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/06/20 01:05:55 UTC

[doris] branch master updated: [improvement](variables) change session variable when set global variable (#10238)

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

yiguolei 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 9a1f1c3864 [improvement](variables) change session variable when set global variable (#10238)
9a1f1c3864 is described below

commit 9a1f1c3864b1a956173101c85b3fd188142df7eb
Author: Mingyu Chen <mo...@gmail.com>
AuthorDate: Mon Jun 20 09:05:50 2022 +0800

    [improvement](variables) change session variable when set global variable (#10238)
    
    Currently, when setting variables with `global` keywords, it will not affect the
    current session variable's value. That is always make user confused.
    
    This CL mainly changes:
    
    1. Change session variable when set global variable
---
 docs/en/docs/advanced/variables.md                 |  4 ++--
 docs/zh-CN/docs/advanced/variables.md              |  7 +++++--
 .../main/java/org/apache/doris/qe/VariableMgr.java | 22 +++++++++++-----------
 .../java/org/apache/doris/qe/VariableMgrTest.java  |  2 ++
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/docs/en/docs/advanced/variables.md b/docs/en/docs/advanced/variables.md
index 1a0c6c1954..a8960c4150 100644
--- a/docs/en/docs/advanced/variables.md
+++ b/docs/en/docs/advanced/variables.md
@@ -43,7 +43,8 @@ SHOW VARIABLES LIKE '%time_zone%';
 
 ### Settings
 
-Some variables can be set at global-level or session-only. For global-level, the set value will be used in subsequent new session connections. For session-only, the variable only works for the current session.
+Note that before version 1.1, after the setting takes effect globally, the setting value will be inherited in subsequent new session connections, but the value in the current session will remain unchanged.
+After version 1.1 (inclusive), after the setting takes effect globally, the setting value will be used in subsequent new session connections, and the value in the current session will also change.
 
 For session-only, set by the `SET var_name=xxx;` statement. Such as:
 
@@ -60,7 +61,6 @@ SET GLOBAL exec_mem_limit = 137438953472
 ```
 
 > Note 1: Only ADMIN users can set variable at global-level.
-> Note 2: Global-level variables do not affect variable values in the current session, only variables in new sessions.
 
 Variables that support both session-level and global-level setting include:
 
diff --git a/docs/zh-CN/docs/advanced/variables.md b/docs/zh-CN/docs/advanced/variables.md
index 3b4395d252..5670c43120 100644
--- a/docs/zh-CN/docs/advanced/variables.md
+++ b/docs/zh-CN/docs/advanced/variables.md
@@ -43,7 +43,10 @@ SHOW VARIABLES LIKE '%time_zone%';
 
 ### 设置
 
-部分变量可以设置全局生效或仅当前会话生效。设置全局生效后,后续新的会话连接中会沿用设置值。而设置仅当前会话生效,则变量仅对当前会话产生作用。
+部分变量可以设置全局生效或仅当前会话生效。
+
+注意,在 1.1 版本之前,设置全局生效后,后续新的会话连接中会沿用设置值,但当前会话中的值不变。
+而在 1.1 版本(含)之后,设置全局生效后,后续新的会话连接中会沿用设置值,当前会话中的值也会改变。
 
 仅当前会话生效,通过 `SET var_name=xxx;` 语句来设置。如:
 
@@ -59,7 +62,7 @@ SET time_zone = "Asia/Shanghai";
 SET GLOBAL exec_mem_limit = 137438953472
 ```
 
-> 注1:只有 ADMIN 用户可以设置变量的全局生效。 注2:全局生效的变量不影响当前会话的变量值,仅影响新的会话中的变量。
+> 注1:只有 ADMIN 用户可以设置变量的全局生效。
 
 既支持当前会话生效又支持全局生效的变量包括:
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
index 6800df1797..287b63a9c1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
@@ -249,19 +249,19 @@ public class VariableMgr {
 
         if (setVar.getType() == SetType.GLOBAL) {
             setGlobalVarAndWriteEditLog(ctx, attr.name(), setVar.getValue().getStringValue());
-        } else {
-            // set session variable
-            Field field = ctx.getField();
-            // if stmt is "Select /*+ SET_VAR(...)*/"
-            if (sessionVariable.getIsSingleSetVar()) {
-                try {
-                    sessionVariable.addSessionOriginValue(field, field.get(sessionVariable).toString());
-                } catch (Exception e) {
-                    LOG.warn("failed to collect origin session value ", e);
-                }
+        }
+
+        // No matter this is a global setting or not, always set session variable.
+        Field field = ctx.getField();
+        // if stmt is "Select /*+ SET_VAR(...)*/"
+        if (sessionVariable.getIsSingleSetVar()) {
+            try {
+                sessionVariable.addSessionOriginValue(field, field.get(sessionVariable).toString());
+            } catch (Exception e) {
+                LOG.warn("failed to collect origin session value ", e);
             }
-            setValue(sessionVariable, field, value);
         }
+        setValue(sessionVariable, field, value);
     }
 
     private static void setGlobalVarAndWriteEditLog(VarContext ctx, String name, String value) throws DdlException {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
index 5654d44ee6..6e7050555a 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
@@ -162,6 +162,8 @@ public class VariableMgrTest {
         SetExecutor executor = new SetExecutor(ctx, stmt);
         executor.execute();
         Assert.assertEquals(5678, VariableMgr.newSessionVariable().getMaxExecMemByte());
+        // the session var is also changed.
+        Assert.assertEquals(5678, ctx.getSessionVariable().getMaxExecMemByte());
 
         Config.edit_log_roll_num = 100;
         stmt = (SetStmt) UtFrameUtils.parseAndAnalyzeStmt("set global exec_mem_limit=7890", ctx);


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