Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs]Fix variable docs of SHOW, SET and UNSET variables #1908

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions docs/sql-manual/sql-statements/session/variable/SET-VARIABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,62 @@ under the License.

This statement is mainly used to modify Doris system variables. These system variables can be modified at the global and session level, and some can also be modified dynamically. You can also view these system variables with `SHOW VARIABLE`.

grammar:
## Syntax

```sql
SET variable_assignment [, variable_assignment] ...
SET variable_assignment [, variable_assignment] [ ... ]
```

illustrate:
Where:
```sql
variable_assignment
: <user_var_name> = <expr>
| [ <effective_scope> ] <system_var_name> = <expr>
```

## Required Parameters
**1. `<user_var_name>`**
> Specifies the variable of user level, for example : @@your_variable_name, variable name starts with `@@`

**2. `<system_var_name>`**
> Specifies the variable of system level, for example : exec_mem_limit and so on

## Optional Parameters
**1. `<effective_scope>`**

> Effective scope is one of `GLOBAL` or `SESSION` or `LOCAL`. If there is no effective scope, default value is `SESSION`. `LOCAL` is an alias of `SESSION`.

1. variable_assignment:
user_var_name = expr
| [GLOBAL | SESSION] system_var_name = expr
## Access Control Requirements
Users executing this SQL command must have at least the following privileges:

> Note:
>
> 1. Only ADMIN users can set variables to take effect globally
> 2. The globally effective variable affects the current session and new sessions thereafter, but does not affect other sessions that currently exist.
| Privilege | Object | Notes |
| :--------- | :----- | :------------------------------------------- |
| ADMIN_PRIV | Session | set global variables need admin privilege |


## Usage Notes

- Only ADMIN users can set variables to take effect globally
- The globally effective variable affects the current session and new sessions thereafter, but does not affect other sessions that currently exist.

## Example
lsy3993 marked this conversation as resolved.
Show resolved Hide resolved

1. Set the time zone to Dongba District
- Set the time zone to East Eighth District

```
SET time_zone = "Asia/Shanghai";
```

2. Set the global execution memory size

- Set the global execution memory size

```
SET GLOBAL exec_mem_limit = 137438953472
```
- Set a user variable

## Keywords
```
SET @@your_variable_name = your_variable_value;
```

SET, VARIABLE

59 changes: 43 additions & 16 deletions docs/sql-manual/sql-statements/session/variable/SHOW-VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,70 @@ under the License.

This statement is used to display Doris system variables, which can be queried by conditions

grammar:
## Syntax

```sql
SHOW [GLOBAL | SESSION] VARIABLES
[LIKE 'pattern' | WHERE expr]
SHOW [<effective_scope>] VARIABLES [<like_pattern> | <where clause>]
```

illustrate:
## Optional Parameters
**1. `<effective_scope>`**
> Effective scope is one of `GLOBAL` or `SESSION` or `LOCAL`. If there is no effective scope, default value is `SESSION`. `LOCAL` is an alias of `SESSION`.

- show variables is mainly used to view the values of system variables.
**2. `<like_pattern>`**
> Use like statement to match and filter result

**3. `<where>`**
> Use where statement to match and filter result

## Access Control Requirements
Users executing this SQL command must have at least the following privileges:

| Privilege | Object | Notes |
| :--------- | :----- | :------------------------------------------- |
| Any_PRIV | Session | Any privilege can show variables |


## Return Value
| Variable_name | Value | Default_Value | Changed |
|:--------------|:--------|:---------------------------------|:--------|
| variable name1 | value1 | default value1 | 0/1 |
| variable name2 | value2 | default value2 | 0/1 |


## Usage Notes

- Show variables is mainly used to view the values of system variables.
- Executing the SHOW VARIABLES command does not require any privileges, it only requires being able to connect to the server.
- Use the like statement to match with variable_name.
- The % percent wildcard can be used anywhere in the matching pattern
- The column `Changed` from `Return Value`, 0 means no changed and 1 means changed.
- There are some restrictions when using the `SHOW` statement:
- Can not use `or` in where clause
- Column names are on the left
- Only supports equivalent comparisons in where clause
- Use the like statement to match with variable_name.
- The % percent wildcard can be used anywhere in the matching pattern


## Example

1. The default here is to match the Variable_name, here is the exact match

- The default here is to match the Variable_name, here is the exact match

```sql
show variables like 'max_connections';
```

2. Matching through the percent sign (%) wildcard can match multiple items

- Matching through the percent sign (%) wildcard can match multiple items

```sql
show variables like '%connec%';
```

3. Use the Where clause for matching queries

- Use the Where clause for matching queries

```sql
show variables where variable_name = 'version';
```

## Keywords

SHOW, VARIABLES

## Best Practice

44 changes: 26 additions & 18 deletions docs/sql-manual/sql-statements/session/variable/UNSET-VARIABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,52 @@ under the License.

This statement is used to restore Doris system variables. These system variables can be modified at global or session level.

grammar:
## Syntax

```sql
UNSET [SESSION|GLOBAL] VARIABLE (variable_name | ALL)
UNSET [<effective_scope>] VARIABLE (<variable_name>)
```

illustrate:
## Required Parameters
**1. `<variable_name>`**
> Specifies the variable name, or if you want to unset all variables, this parameter you can give a keyword `ALL`.

## Optional Parameters
**1. `<effective_scope>`**
> Effective scope is one of `GLOBAL` or `SESSION` or `LOCAL`. If there is no effective scope, default value is `SESSION`. `LOCAL` is an alias of `SESSION`.

## Access Control Requirements
Users executing this SQL command must have at least the following privileges:

| Privilege | Object | Notes |
| :--------- | :----- | :------------------------------------------- |
| ADMIN_PRIV | Session | unset global variables need admin privilege |

## Usage Notes

- Only ADMIN users can unset variables to take effect globally
- When restore a variable with `GLOBAL`, it only affects your current using session and new open sessions. It does not affect other current open sessions.

1. (variable_name | ALL): statement must be ended with a variable name or keyword `ALL`.

> Note:
>
> 1. Only ADMIN users can unset variables to take effect globally
> 2. When restore a variable with `GLOBAL`, it only affect your current using session and new open sessions. It does not affect other current open sessions.

## Example

1. Restore value of the time zone
- Restore value of the time zone

```
UNSET VARIABLE time_zone;
```

2. Restore the global execution memory size

- Restore the global execution memory size

```
UNSET GLOBAL VARIABLE exec_mem_limit;
```

3. Restore all variables globally

- Restore all variables globally

```
UNSET GLOBAL VARIABLE ALL;
```

## Keywords

UNSET, VARIABLE

## Best Practice

Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,59 @@ under the License.

该语句主要是用来修改 Doris 系统变量,这些系统变量可以分为全局以及会话级别层面来修改,有些也可以进行动态修改。你也可以通过 `SHOW VARIABLE` 来查看这些系统变量。

语法:

## 语法
```sql
SET variable_assignment [, variable_assignment] [ ... ]
```
其中
```sql
SET variable_assignment [, variable_assignment] ...
variable_assignment
: <user_var_name> = <expr>
| [ <effective_scope> ] <system_var_name> = <expr>
```

说明:
## 必选参数
**1. `<user_var_name>`**
> 指定用户层级的变量,比如:@@your_variable_name 等以`@@`开头的变量名称

**2. `<system_var_name>`**
> 指定系统层级的变量,比如exec_mem_limit 等

## 可选参数
**1. `<effective_scope>`**

> 生效范围的取值可以是`GLOBAL`或者`SESSION`或者`LOCAL`之一,如果不指定该值,默认为`SESSION`。`LOCAL`是`SESSION`的一个别名。

## 权限控制
执行此 SQL 命令的用户必须至少具有以下权限:

1. variable_assignment:
user_var_name = expr
| [GLOBAL | SESSION] system_var_name = expr
| Privilege | Object | Notes |
| :--------- | :----- | :------------------------------------------- |
| ADMIN_PRIV | Session | set global variables 需要 admin 权限 |

> 注意:
>
> 1. 只有 ADMIN 用户可以设置变量的全局生效
> 2. 全局生效的变量影响当前会话和此后的新会话,不影响当前已经存在的其他会话。
## 注意事项

- 只有 ADMIN 用户可以设置变量的全局生效
- 全局生效的变量影响当前会话和此后的新会话,不影响当前已经存在的其他会话。

## 示例

1. 设置时区为东八区

- 设置时区为东八区

```
SET time_zone = "Asia/Shanghai";
```

2. 设置全局的执行内存大小

- 设置全局的执行内存大小

```
SET GLOBAL exec_mem_limit = 137438953472
```

## 关键词

SET, VARIABLE
- 设置用户变量
```
SET @@your_variable_name = your_variable_value;
```

Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,68 @@ under the License.

该语句是用来显示 Doris 系统变量,可以通过条件查询

语法:
## 语法

```sql
SHOW [GLOBAL | SESSION] VARIABLES
[LIKE 'pattern' | WHERE expr]
SHOW [<effective_scope>] VARIABLES [<like_pattern> | <where>]
```

说明:
## 可选参数
**1. `<effective_scope>`**
> 生效范围的取值可以是`GLOBAL`或者`SESSION`或者`LOCAL`之一,如果不指定该值,默认为`SESSION`。`LOCAL`是`SESSION`的一个别名。

**2. `<like_pattern>`**
> 使用like语句去匹配和过滤最终结果

**3. `<where>`**
> 使用where语句去匹配和过滤最终结果

## 权限控制
执行此 SQL 命令的用户必须至少具有以下权限:

| Privilege | Object | Notes |
| :--------- | :----- | :------------------------------------------- |
| Any_PRIV | Session | SHOW VARIABLES 命令不需要任何权限 |


## 返回值
| Variable_name | Value | Default_Value | Changed |
|:--------------|:--------|:---------------------------------|:--------|
| variable name1 | value1 | default value1 | 0/1 |
| variable name2 | value2 | default value2 | 0/1 |

## 注意事项

- show variables 主要是用来查看系统变量的值。
- 执行 SHOW VARIABLES 命令不需要任何权限,只要求能够连接到服务器就可以。
- 使用 like 语句表示用 variable_name 进行匹配。
- %百分号通配符可以用在匹配模式中的任何位置
- 返回值部分中的`Changed`列,0表示没有改变过,1表示改变过。
- 使用`SHOW`语句的一些限制:
- where 语法中不能使用`or`语句
- 列名在等值左侧
- 只支持等值连接
- 使用 like 语句表示用 variable_name 进行匹配。
- %百分号通配符可以用在匹配模式中的任何位置。


## 示例

1. 这里默认的就是对 Variable_name 进行匹配,这里是准确匹配

- 这里默认的就是对 Variable_name 进行匹配,这里是准确匹配

```sql
show variables like 'max_connections';
```

2. 通过百分号 (%) 这个通配符进行匹配,可以匹配多项

- 通过百分号 (%) 这个通配符进行匹配,可以匹配多项

```sql
show variables like '%connec%';
```

3. 使用 Where 子句进行匹配查询

- 使用 Where 子句进行匹配查询

```sql
show variables where variable_name = 'version';
```

## 关键词

SHOW, VARIABLES

### 最佳实践

Loading
Loading