MySQL - ALTER RESOURCE GROUP Statement



In MySQL you can create resource groups and assign threads to these groups. These threads execute based on the availability of the resources in the group i.e. the group attributes controls the resources and the threads in the group are restricted to the available resources.

MySQL provides various statements to create, alter, drop a group resource and assign threads to a group resource.

ALTER RESOURCE GROUP Statement

You can modify the CPU affinity, thread priority values of an existing resource group using the MySQL ALTER RESOURCE GROUP Statement. Using this you can also modify the initial state (ENABLE or DISABLE) of a resource group. You need RESOURCE_GROUP_ADMIN privileges to execute the statement.

Syntax

Following is the syntax of the MySQL ALTER RESOURCE GROUP Statement −

ALTER RESOURCE GROUP group_name
[VCPU [=] vcpu_spec [, vcpu_spec] ...]
[THREAD_PRIORITY [=] N]
[ENABLE|DISABLE]

Where, group_name is the name of the group you need to modify.

Altering the CPU affinity

The VPU attribute of the CREATE RESOURCE GROUP Statement is used to set the CPU affinity for the resource group. If you haven't passed this value then the group uses all available CPUs.

Assume we have created a resource group by providing some value to CPU affinity as shown below −

CREATE RESOURCE GROUP sample_group1 TYPE = USER VCPU = 0,1,2,3;

Following query changes the CPU affinity value of the above created resource group −

ALTER RESOURCE GROUP sample_group1 VCPU = 0;

The thread priority attribute

The thread priority attribute is used to set the priority of the thread to be created, if you haven't passed this value, the default value is set to 0. The priority range for a thread in a resource group is -20 to 19.

Assume we have created a resource and assigned the thread priority value to 2 as shown below −

CREATE RESOURCE GROUP sample_group2 
TYPE = USER VCPU = 0 THREAD_PRIORITY = 2;

Following query alters the thread priority of the above created query −

ALTER RESOURCE GROUP sample_group2 THREAD_PRIORITY = 15;

The ENABLE attribute

If you use the ENABLE (attribute value) in the query the resource group is initially enabled in the same way if you specify DISABLE in the statement the resource group is initially disabled.

Assume we have created a resource group by setting this value to DISABLE as shown below −

CREATE RESOURCE GROUP sample_group3 TYPE = USER 
VCPU = 0 THREAD_PRIORITY = 2 DISABLE;

Following query modifies the above created resource group −

ALTER RESOURCE GROUP sample_group3 ENABLE;

Altering a resource group that doesn't exist

If you try to alter the resource group that does not exist an error is generated as follows −

ALTER RESOURCE GROUP none THREAD_PRIORITY = 15;
ERROR 3651 (HY000): Resource Group 'none' does not exist.
Advertisements