Skip to content

Commit

Permalink
resource_control: add description for current resource group (#14515)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv authored Aug 10, 2023
1 parent e896547 commit 3172540
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion functions-and-operators/information-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TiDB 支持使用 MySQL 5.7 中提供的大部分[信息函数](https://dev.mysq

| 函数名 | 功能描述 |
| ------ | ---------------------------------------- |
| `CURRENT_RESOURCE_GROUP()` | 返回当前连接的资源组名 |
| [`CURRENT_RESOURCE_GROUP()`](/functions-and-operators/tidb-functions.md#current_resource_group) | 返回当前连接的资源组名 |

## TiDB 不支持的信息函数

Expand Down
48 changes: 48 additions & 0 deletions functions-and-operators/tidb-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,51 @@ SELECT *, TIDB_ROW_CHECKSUM() FROM t WHERE id = 1;
+----+------+------+---------------------+
1 row in set (0.000 sec)
```
### CURRENT_RESOURCE_GROUP
`CURRENT_RESOURCE_GROUP` 函数用于查询当前连接绑定的资源组名称。当开启[资源管控 (Resource Control)](/tidb-resource-control.md) 功能时,执行 SQL 语句对资源的占用会受到所绑定的资源组资源配置的限制。
在会话建立时,TiDB 默认会将连接绑定至登录用户绑定的资源组,如果用户没有绑定任何资源组,则会将连接绑定至 `default` 资源组。在会话建立之后,绑定的资源组默认不会发生变化,即使执行了[修改用户绑定的资源组](/sql-statements/sql-statement-alter-user.md#修改用户绑定的资源组)。如需修改当前会话绑定的资源组,可以使用 [`SET RESOURCE GROUP`](/sql-statements/sql-statement-set-resource-group.md) 语句。
#### 示例
创建一个用户 `user1`,创建两个资源组 `rg1` 和 `rg2`,并将用户 `user1` 绑定资源组 `rg1`:
```sql
CREATE USER 'user1';
CREATE RESOURCE GROUP 'rg1' RU_PER_SEC = 1000;
CREATE RESOURCE GROUP 'rg2' RU_PER_SEC = 2000;
ALTER USER 'user1' RESOURCE GROUP `rg1`;
```
使用 `user1` 登录,查看当前用户绑定的资源组:
```sql
SELECT CURRENT_RESOURCE_GROUP();
```
```sql
+--------------------------+
| CURRENT_RESOURCE_GROUP() |
+--------------------------+
| rg1 |
+--------------------------+
1 row in set (0.00 sec)
```
执行 `SET RESOURCE GROUP` 将当前会话的资源组设置为 `rg2`,然后查看当前用户绑定的资源组:
```sql
SET RESOURCE GROUP `rg2`;
SELECT CURRENT_RESOURCE_GROUP();
```
```sql
+--------------------------+
| CURRENT_RESOURCE_GROUP() |
+--------------------------+
| rg2 |
+--------------------------+
1 row in set (0.00 sec)
```

0 comments on commit 3172540

Please sign in to comment.