SET RESOURCE GROUP

SET RESOURCE GROUP is used to set the resource group for the current session.

SET RESOURCE GROUP - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

SetResourceGroupStmt:

SetResourceGroupStmt

SET RESOURCE GROUP - 图2

ResourceGroupName

SET RESOURCE GROUP - 图3

  1. SetResourceGroupStmt ::=
  2. "SET" "RESOURCE" "GROUP" ResourceGroupName
  3. ResourceGroupName ::=
  4. Identifier

Examples

Create a user user1, create two resource groups rg1 and rg2, and bind the user user1 to the resource group rg1.

  1. CREATE USER 'user1';
  2. CREATE RESOURCE GROUP 'rg1' RU_PER_SEC = 1000;
  3. ALTER USER 'user1' RESOURCE GROUP `rg1`;

Use user1 to log in and view the resource group bound to the current user.

  1. SELECT CURRENT_RESOURCE_GROUP();
  1. +--------------------------+
  2. | CURRENT_RESOURCE_GROUP() |
  3. +--------------------------+
  4. | rg1 |
  5. +--------------------------+
  6. 1 row in set (0.00 sec)

Execute SET RESOURCE GROUP to set the resource group for the current session to rg2.

  1. SET RESOURCE GROUP `rg2`;
  2. SELECT CURRENT_RESOURCE_GROUP();
  1. +--------------------------+
  2. | CURRENT_RESOURCE_GROUP() |
  3. +--------------------------+
  4. | rg2 |
  5. +--------------------------+
  6. 1 row in set (0.00 sec)

Execute SET RESOURCE GROUP to specify the current session to use the default resource group.

  1. SET RESOURCE GROUP `default`;
  2. SELECT CURRENT_RESOURCE_GROUP();
  1. +--------------------------+
  2. | CURRENT_RESOURCE_GROUP() |
  3. +--------------------------+
  4. | default |
  5. +--------------------------+
  6. 1 row in set (0.00 sec)

MySQL compatibility

MySQL also supports SET RESOURCE GROUP. But the accepted parameters are different from that of TiDB. They are not compatible.

See also