SET RESOURCE GROUP
SET RESOURCE GROUP is used to set the resource group for the current session.
Synopsis
SetResourceGroupStmt:
- SetResourceGroupStmt
- ResourceGroupName
SetResourceGroupStmt ::=
"SET" "RESOURCE" "GROUP" ResourceGroupName
ResourceGroupName ::=
Identifier
| "DEFAULT"
Privilege
Executing this statement requires the following configuration and privilege:
- The system variable
tidb_enable_resource_controlis set toON. - When the system variable
tidb_resource_control_strict_modeis set toON, you need to have theSUPERorRESOURCE_GROUP_ADMINorRESOURCE_GROUP_USERprivilege; when it is set toOFF, none of these privileges are required.
Examples
Create a user user1, create two resource groups rg1 and rg2, and bind the user user1 to the resource group rg1.
CREATE USER 'user1';
CREATE RESOURCE GROUP 'rg1' RU_PER_SEC = 1000;
ALTER USER 'user1' RESOURCE GROUP `rg1`;
Use user1 to log in and view the resource group bound to the current user.
SELECT CURRENT_RESOURCE_GROUP();
+--------------------------+
| CURRENT_RESOURCE_GROUP() |
+--------------------------+
| rg1 |
+--------------------------+
1 row in set (0.00 sec)
Execute SET RESOURCE GROUP to set the resource group for the current session to rg2.
SET RESOURCE GROUP `rg2`;
SELECT CURRENT_RESOURCE_GROUP();
+--------------------------+
| CURRENT_RESOURCE_GROUP() |
+--------------------------+
| rg2 |
+--------------------------+
1 row in set (0.00 sec)
Execute SET RESOURCE GROUP to specify the current session to use the default resource group.
SET RESOURCE GROUP `default`;
SELECT CURRENT_RESOURCE_GROUP();
+--------------------------+
| CURRENT_RESOURCE_GROUP() |
+--------------------------+
| default |
+--------------------------+
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.