CREATE RESOURCE GROUP

You can use the CREATE RESOURCE GROUP statement to create a resource group.

CREATE RESOURCE GROUP - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

CreateResourceGroupStmt

CREATE RESOURCE GROUP - 图2

IfNotExists

CREATE RESOURCE GROUP - 图3

ResourceGroupName

CREATE RESOURCE GROUP - 图4

ResourceGroupOptionList

CREATE RESOURCE GROUP - 图5

DirectResourceGroupOption

CREATE RESOURCE GROUP - 图6

ResourceGroupPriorityOption

CREATE RESOURCE GROUP - 图7

ResourceGroupRunawayOptionList

CREATE RESOURCE GROUP - 图8

DirectResourceGroupRunawayOption

CREATE RESOURCE GROUP - 图9

WatchDurationOption

CREATE RESOURCE GROUP - 图10

ResourceGroupRunawayWatchOption

CREATE RESOURCE GROUP - 图11

ResourceGroupRunawayActionOption

CREATE RESOURCE GROUP - 图12

  1. CreateResourceGroupStmt ::=
  2. "CREATE" "RESOURCE" "GROUP" IfNotExists ResourceGroupName ResourceGroupOptionList
  3. IfNotExists ::=
  4. ('IF' 'NOT' 'EXISTS')?
  5. ResourceGroupName ::=
  6. Identifier
  7. | "DEFAULT"
  8. ResourceGroupOptionList ::=
  9. DirectResourceGroupOption
  10. | ResourceGroupOptionList DirectResourceGroupOption
  11. | ResourceGroupOptionList ',' DirectResourceGroupOption
  12. DirectResourceGroupOption ::=
  13. "RU_PER_SEC" EqOpt stringLit
  14. | "PRIORITY" EqOpt ResourceGroupPriorityOption
  15. | "BURSTABLE"
  16. | "BURSTABLE" EqOpt Boolean
  17. | "QUERY_LIMIT" EqOpt '(' ResourceGroupRunawayOptionList ')'
  18. | "QUERY_LIMIT" EqOpt '(' ')'
  19. | "QUERY_LIMIT" EqOpt "NULL"
  20. | "BACKGROUND" EqOpt '(' BackgroundOptionList ')'
  21. | "BACKGROUND" EqOpt '(' ')'
  22. | "BACKGROUND" EqOpt "NULL"
  23. ResourceGroupPriorityOption ::=
  24. LOW
  25. | MEDIUM
  26. | HIGH
  27. ResourceGroupRunawayOptionList ::=
  28. DirectResourceGroupRunawayOption
  29. | ResourceGroupRunawayOptionList DirectResourceGroupRunawayOption
  30. | ResourceGroupRunawayOptionList ',' DirectResourceGroupRunawayOption
  31. DirectResourceGroupRunawayOption ::=
  32. "EXEC_ELAPSED" EqOpt stringLit
  33. | "ACTION" EqOpt ResourceGroupRunawayActionOption
  34. | "WATCH" EqOpt ResourceGroupRunawayWatchOption WatchDurationOption
  35. WatchDurationOption ::=
  36. ("DURATION" EqOpt stringLit | "DURATION" EqOpt "UNLIMITED")?
  37. ResourceGroupRunawayWatchOption ::=
  38. EXACT
  39. | SIMILAR
  40. | PLAN
  41. ResourceGroupRunawayActionOption ::=
  42. DRYRUN
  43. | COOLDOWN
  44. | KILL

The resource group name parameter (ResourceGroupName) must be globally unique.

TiDB supports the following DirectResourceGroupOption, where Request Unit (RU) is a unified abstraction unit in TiDB for CPU, IO, and other system resources.

OptionDescriptionExample
RU_PER_SECRate of RU backfilling per secondRU_PER_SEC = 500 indicates that this resource group is backfilled with 500 RUs per second
PRIORITYThe absolute priority of tasks to be processed on TiKVPRIORITY = HIGH indicates that the priority is high. If not specified, the default value is MEDIUM.
BURSTABLEIf the BURSTABLE attribute is set, TiDB allows the corresponding resource group to use the available system resources when the quota is exceeded.
QUERY_LIMITWhen the query execution meets this condition, the query is identified as a runaway query and the corresponding action is executed.QUERY_LIMIT=(EXEC_ELAPSED=’60s’, ACTION=KILL, WATCH=EXACT DURATION=’10m’) indicates that the query is identified as a runaway query when the execution time exceeds 60 seconds. The query is terminated. All SQL statements with the same SQL text will be terminated immediately in the coming 10 minutes. QUERY_LIMIT=() or QUERY_LIMIT=NULL means that runaway control is not enabled. See Runaway Queries.

CREATE RESOURCE GROUP - 图13

Note

  • The CREATE RESOURCE GROUP statement can only be executed when the global variable tidb_enable_resource_control is set to ON. TiDB automatically creates a default resource group during cluster initialization. For this resource group, the default value of RU_PER_SEC is UNLIMITED (equivalent to the maximum value of the INT type, that is, 2147483647) and it is in BURSTABLE mode. All requests that are not bound to any resource group are automatically bound to this default resource group. When you create a new configuration for another resource group, it is recommended to modify the default resource group configuration as needed.
  • Currently, only the default resource group supports modifying the BACKGROUND configuration.

Examples

Create two resource groups rg1 and rg2.

  1. DROP RESOURCE GROUP IF EXISTS rg1;
  1. Query OK, 0 rows affected (0.22 sec)
  1. CREATE RESOURCE GROUP IF NOT EXISTS rg1
  2. RU_PER_SEC = 100
  3. PRIORITY = HIGH
  4. BURSTABLE;
  1. Query OK, 0 rows affected (0.08 sec)
  1. CREATE RESOURCE GROUP IF NOT EXISTS rg2
  2. RU_PER_SEC = 200 QUERY_LIMIT=(EXEC_ELAPSED='100ms', ACTION=KILL);
  1. Query OK, 0 rows affected (0.08 sec)
  1. SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1' or NAME = 'rg2';
  1. +------+------------+----------+-----------+---------------------------------+
  2. | NAME | RU_PER_SEC | PRIORITY | BURSTABLE | QUERY_LIMIT |
  3. +------+------------+----------+-----------+---------------------------------+
  4. | rg1 | 100 | HIGH | YES | NULL |
  5. | rg2 | 200 | MEDIUM | NO | EXEC_ELAPSED=100ms, ACTION=KILL |
  6. +------+------------+----------+-----------+---------------------------------+
  7. 2 rows in set (1.30 sec)

MySQL compatibility

MySQL also supports CREATE RESOURCE GROUP. However, the acceptable parameters are different from that of TiDB so that they are not compatible.

See also