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

resource_control: add new privilege RESOURCE_GROUP_USER #17681

Merged
merged 15 commits into from
Jun 27, 2024
4 changes: 4 additions & 0 deletions optimizer-hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ SELECT /*+ NTH_PLAN(3) */ count(*) from t where a > 5;
SELECT /*+ RESOURCE_GROUP(rg1) */ * FROM t limit 10;
```

> **注意:**
>
> - 要使用此 Hint,你需要有 `SUPER` 或者 `RESOURCE_GROUP_ADMIN` 或者 `RESOURCE_GROUP_USER` 权限。如果你没有所需权限,则此 Hint 会被忽略,同时 TiDB 会返回 warning,你可以在查询结束后通过 `SHOW WARNINGS;` 命令查看具体信息。
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

## 常见 Hint 不生效问题排查

### MySQL 命令行客户端清除 Hint 导致不生效
Expand Down
4 changes: 4 additions & 0 deletions privilege-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ SELECT * FROM INFORMATION_SCHEMA.USER_PRIVILEGES WHERE grantee = "'root'@'%'";

需要拥有 `SUPER` 或者 `RESOURCE_GROUP_ADMIN` 权限。

### SET RESOURCE GROUP

当全局变量 [`tidb_resource_control_strict_mode`](/system-variables.md#tidb_resource_control_strict_mode-从-v820-版本开始引入) 设置为 `ON` 时,你需要拥有 `SUPER` 或者 `RESOURCE_GROUP_ADMIN` 或者 `RESOURCE_GROUP_USER` 权限才能执行才语句。
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

lilin90 marked this conversation as resolved.
Show resolved Hide resolved
## 权限系统的实现

### 授权表
Expand Down
7 changes: 7 additions & 0 deletions sql-statements/sql-statement-set-resource-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ ResourceGroupName ::=
| "DEFAULT"
```

## 权限

执行此命令依赖如下配置和权限:

- [`tidb_enable_resource_control`](/system-variables.md#tidb_enable_resource_control-从-v660-版本开始引入) 设置为 `ON`
- 全局变量 [`tidb_resource_control_strict_mode`](/system-variables.md#tidb_resource_control_strict_mode-从-v820-版本开始引入) 设置为 `ON`,并且你拥有 `SUPER` 或者 `RESOURCE_GROUP_ADMIN` 或者 `RESOURCE_GROUP_USER` 权限
lilin90 marked this conversation as resolved.
Show resolved Hide resolved

## 示例

创建一个用户 `user1`,创建两个资源组 `rg1` 和 `rg2`,并将用户 `user1` 绑定资源组 `rg1`。
Expand Down
3 changes: 2 additions & 1 deletion sql-statements/sql-statement-show-privileges.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ SHOW PRIVILEGES;
| RESTRICTED_CONNECTION_ADMIN | Server Admin | |
| RESTRICTED_REPLICA_WRITER_ADMIN | Server Admin | |
| RESOURCE_GROUP_ADMIN | Server Admin | |
| RESOURCE_GROUP_USER | Server Admin | |
+---------------------------------+---------------------------------------+-------------------------------------------------------+
49 rows in set (0.00 sec)
50 rows in set (0.00 sec)
```

## MySQL 兼容性
Expand Down
10 changes: 10 additions & 0 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4380,6 +4380,16 @@ EXPLAIN FORMAT='brief' SELECT COUNT(1) FROM t WHERE a = 1 AND b IS NOT NULL;
- 可选值:`"ddl"`、`"stats"`、`"br"`、`"lightning"`、`"background"`
- 显式指定当前会话的任务类型,用于[资源管控](/tidb-resource-control.md)识别并控制。如 `SET @@tidb_request_source_type = "background"`。

### `tidb_resource_control_strict_mode` <span class="version-mark">从 v8.2.0 版本开始引入</span>

- 作用域:GLOBAL
- 是否持久化到集群:是
- 是否受 Hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value) 控制:否
- 类型:布尔型
- 默认值:`ON`
- 该变量是 [SET RESOURCE GROUP](/sql-statements/sql-statement-set-resource-group.md) 和优化器 [`RESOURCE_GROUP()`](/optimizer-hints.md#resource_groupresource_group_name) Hint 权限控制的开关。当此变量设置为 `ON` 时,你需要具有对应的权限才能使用这两种方式修改当前会话或当前语句绑定的资源组。
lilin90 marked this conversation as resolved.
Show resolved Hide resolved
- 从旧版本升级到 v8.2.0 及之后版本时,该功能默认关闭,此时该变量默认值为 `OFF`。

### `tidb_retry_limit`

- 作用域:SESSION | GLOBAL
Expand Down