CREATE RESOURCE GROUP
CREATE RESOURCE GROUP
语句用于在当前所选数据库中创建资源组。
语法图
- CreateResourceGroupStmt
- IfNotExists
- ResourceGroupName
- ResourceGroupOptionList
- DirectResourceGroupOption
- ResourceGroupPriorityOption
- ResourceGroupRunawayOptionList
- DirectResourceGroupRunawayOption
- WatchDurationOption
- ResourceGroupRunawayWatchOption
- ResourceGroupRunawayActionOption
CreateResourceGroupStmt ::=
"CREATE" "RESOURCE" "GROUP" IfNotExists ResourceGroupName ResourceGroupOptionList
IfNotExists ::=
('IF' 'NOT' 'EXISTS')?
ResourceGroupName ::=
Identifier
| "DEFAULT"
ResourceGroupOptionList ::=
DirectResourceGroupOption
| ResourceGroupOptionList DirectResourceGroupOption
| ResourceGroupOptionList ',' DirectResourceGroupOption
DirectResourceGroupOption ::=
"RU_PER_SEC" EqOpt stringLit
| "PRIORITY" EqOpt ResourceGroupPriorityOption
| "BURSTABLE"
| "BURSTABLE" EqOpt Boolean
| "QUERY_LIMIT" EqOpt '(' ResourceGroupRunawayOptionList ')'
| "QUERY_LIMIT" EqOpt '(' ')'
| "QUERY_LIMIT" EqOpt "NULL"
| "BACKGROUND" EqOpt '(' BackgroundOptionList ')'
| "BACKGROUND" EqOpt '(' ')'
| "BACKGROUND" EqOpt "NULL"
ResourceGroupPriorityOption ::=
LOW
| MEDIUM
| HIGH
ResourceGroupRunawayOptionList ::=
DirectResourceGroupRunawayOption
| ResourceGroupRunawayOptionList DirectResourceGroupRunawayOption
| ResourceGroupRunawayOptionList ',' DirectResourceGroupRunawayOption
DirectResourceGroupRunawayOption ::=
"EXEC_ELAPSED" EqOpt stringLit
| "PROCESSED_KEYS" EqOpt intLit
| "RU" EqOpt intLit
| "ACTION" EqOpt ResourceGroupRunawayActionOption
| "WATCH" EqOpt ResourceGroupRunawayWatchOption WatchDurationOption
WatchDurationOption ::=
("DURATION" EqOpt stringLit | "DURATION" EqOpt "UNLIMITED")?
ResourceGroupRunawayWatchOption ::=
EXACT
| SIMILAR
| PLAN
ResourceGroupRunawayActionOption ::=
DRYRUN
| COOLDOWN
| KILL
| "SWITCH_GROUP" '(' ResourceGroupName ')'
资源组的 ResourceGroupName
是全局唯一的,不允许重复。
TiDB 支持以下 DirectResourceGroupOption
, 其中 Request Unit (RU) 是 TiDB 对 CPU、IO 等系统资源统一抽象的单位。
参数 | 含义 | 举例 |
---|---|---|
RU_PER_SEC | 每秒 RU 填充的速度 | RU_PER_SEC = 500 表示此资源组每秒回填 500 个 RU。 |
PRIORITY | 任务在 TiKV 上处理的绝对优先级 | PRIORITY = HIGH 表示优先级高。若未指定,则默认为 MEDIUM 。 |
BURSTABLE | 允许对应的资源组超出配额后使用空余的系统资源。 | |
QUERY_LIMIT | 当查询执行满足该条件时,识别该查询为 Runaway Query 并进行相应的控制 | QUERY_LIMIT=(EXEC_ELAPSED='60s', ACTION=KILL, WATCH=EXACT DURATION='10m') 表示当执行时间超过 60 秒后识别为 Runaway Query,对该查询执行终止操作,并在 10 分钟内对同样的 SQL 直接执行终止操作。QUERY_LIMIT=() 或 QUERY_LIMIT=NULL 则表示不进行 Runaway 控制。具体参数介绍详见管理资源消耗超出预期的查询 (Runaway Queries)。 | |
示例
创建 rg1
和 rg2
两个资源组。
DROP RESOURCE GROUP IF EXISTS rg1;
Query OK, 0 rows affected (0.22 sec)
CREATE RESOURCE GROUP IF NOT EXISTS rg1
RU_PER_SEC = 100
PRIORITY = HIGH
BURSTABLE;
Query OK, 0 rows affected (0.08 sec)
CREATE RESOURCE GROUP IF NOT EXISTS rg2
RU_PER_SEC = 200 QUERY_LIMIT=(EXEC_ELAPSED='100ms', ACTION=KILL);
Query OK, 0 rows affected (0.08 sec)
SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1' or NAME = 'rg2';
+------+------------+----------+-----------+---------------------------------+
| NAME | RU_PER_SEC | PRIORITY | BURSTABLE | QUERY_LIMIT |
+------+------------+----------+-----------+---------------------------------+
| rg1 | 100 | HIGH | YES | NULL |
| rg2 | 200 | MEDIUM | NO | EXEC_ELAPSED=100ms, ACTION=KILL |
+------+------------+----------+-----------+---------------------------------+
2 rows in set (1.30 sec)
MySQL 兼容性
MySQL 也支持 CREATE RESOURCE GROUP,但是接受的参数和 TiDB 不同,两者并不兼容。