SET STATEMENT
Contents
SET STATEMENT#
SET
语句用于在 OpenMLDB 上设置系统变量。目前OpenMLDB的系统变量包括会话系统变量和全局系统变量。对会话变量的修改,只会影响到当前的会话(也就是当前的数据库连接)。对全局变量的修改会对所有会话生效。
Syntax#
SetStatement ::=
'SET' variableName '=' value
variableName ::=
sessionVariableName
sessionVariableName ::= '@@'Identifier | '@@session.'Identifier | '@@global.'Identifier
或者用下面的语法格式
'SET' [ GLOBAL | SESSION ] <variableName> '=' <value>
会话系统变量一般以
@session前缀
,如SET @@session.execute_mode = "offline";
。会话系统变量也可以选择直接以@@
为前缀,即SET @@execute_mode = "offline"
和前面的配置语句是等价的。全局系统变量以
@global为前缀
,如SET @@global.enable_trace = true;
会话系统变量也可以选择直接以
@@
为前缀,即SET @@execute_mode = "offline"
和前面的配置语句是等价的。OpenMLDB的SET语句只能用于设置/修改已存在(内置的)的系统变量。
目前支持的系统变量#
SESSION 系统变量#
SESSION系统变量 |
变量描述 |
变量值 |
默认值 |
---|---|---|---|
@@session.execute_mode|@@execute_mode |
OpenMDLB在当前会话下的执行模式。目前支持 |
“offline” | “online” |
“offline” |
@@session.enable_trace|@@enable_trace |
当该变量值为 |
“true” | “false” |
“false” |
@@session.sync_job|@@sync_job |
当该变量值为 |
“true” | “false” |
“false” |
@@session.sync_timeout|@@sync_timeout |
当sync_job值为 |
Int |
“20000” |
Example#
设置和显示会话系统变量#
> SHOW VARIABLES;
--------------- ---------
Variable_name Value
--------------- ---------
enable_trace false
execute_mode offline
job_timeout 20000
sync_job false
--------------- ---------
4 rows in set
> SET @@session.execute_mode = "online";
-- SUCCEED
> SHOW VARIABLES;
--------------- ---------
Variable_name Value
--------------- ---------
enable_trace false
execute_mode online
job_timeout 20000
sync_job false
--------------- ---------
4 rows in set
> SET @@session.enable_trace = "true";
-- SUCCEED
> SHOW VARIABLES;
--------------- ---------
Variable_name Value
--------------- ---------
enable_trace true
execute_mode online
job_timeout 20000
sync_job false
--------------- ---------
4 rows in set
设置和显示全局系统变量#
> SHOW GLOBAL VARIABLES;
--------------- ----------------
Variable_name Variable_value
--------------- ----------------
enable_trace false
sync_job false
job_timeout 20000
execute_mode offline
--------------- ----------------
4 rows in set
> SET @@global.enable_trace = "true";
-- SUCCEED
> SHOW GLOBAL VARIABLES;
--------------- ----------------
Variable_name Variable_value
--------------- ----------------
enable_trace true
sync_job false
job_timeout 20000
execute_mode offline
--------------- ----------------
4 rows in set
配置enable_trace#
创建一个数据库
db1
,并建立表t1
CREATE DATABASE db1;
-- SUCCEED
USE db1;
-- SUCCEED: Database changed
CREATE TABLE t1 (col0 STRING, col1 int, std_time TIMESTAMP, INDEX(KEY=col1, TS=std_time, TTL_TYPE=absolute, TTL=30d));
--SUCCEED
关闭enable_trace时,执行错误的SQL:
> set @@enable_trace = "false";
-- SUCCEED
> select sum(col1) over w1 from t1 window w1 as (partition by col1 order by col0 rows_range between 10d preceding and current row);
-- ERROR: Invalid Order column type : kVarchar
打开enable_trace时,执行错误的SQL:
> set @@enable_trace = "true";
-- SUCCEED
> select sum(col1) over w1 from t1 window w1 as (partition by col1 order by col0 rows_range between 10d preceding and current row);
-- ERROR: Invalid Order column type : kVarchar
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/sql_compiler.cc:263)
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/sql_compiler.cc:166)
(Caused by) Fail to generate physical plan batch mode
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/transform.cc:1672)
(Caused by) Fail to transform query statement
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/transform.cc:103)
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/transform.cc:1249)
(At /Users/chenjing/work/chenjing/OpenMLDB/hybridse/src/vm/transform.cc:1997)
配置离线命令同步执行#
设置离线命令同步执行:
> SET @@sync_job = "true";
设置同步命令的等待时间(单位为毫秒):
> SET @@job_timeout = "600000";