Skip to main content
Version: 3.2

CREATE RESOURCE GROUP

Description

Creates a resource group.

For more information, see Resource group.

tip

This operation requires the SYSTEM-level CREATE RESOURCE GROUP privilege. You can follow the instructions in GRANT to grant this privilege.

Syntax

CREATE RESOURCE GROUP resource_group_name 
TO CLASSIFIER1, CLASSIFIER2, ...
WITH resource_limit

Parameters

  • resource_group_name: The name of the resource group to be created.

  • CLASSIFIER: Classifiers used to filter the queries on which resource limits are imposed. You must specify a classifier using "key"="value" pairs. You can set multiple classifiers for a resource group.

    Parameters for classifiers are listed below:

    ParameterRequiredDescription
    userNoThe name of user.
    roleNoThe role of user.
    query_typeNoThe type of query. SELECT and INSERT (from v2.5) are supported. When INSERT tasks hit a resource group with query_type as insert, the BE node reserves the specified CPU resources for the tasks.
    source_ipNoThe CIDR block from which the query is initiated.
    dbNoThe database which the query accesses. It can be specified by strings separated by commas (,).
    plan_cpu_cost_rangeNoThe estimated CPU cost range of the query. Its value has an equivalent meaning with the field PlanCpuCost in fe.audit.log, and has no unit. The format is [DOUBLE, DOUBLE). The default value is NULL, indicating no such restriction. This parameter is supported from v3.1.4 onwards.
    plan_mem_cost_rangeNoThe estimated memory cost range of the query. Its value has an equivalent meaning with the field PlanMemCost in fe.audit.log, and has no unit. The format is [DOUBLE, DOUBLE). The default value is NULL, indicating no such restriction. This parameter is supported from v3.1.4 onwards.
  • resource_limit: Resource limits to be imposed on the resource group. You must specify resource limits using "key"="value" pairs. You can set multiple resource limits for a resource group.

    Parameters for resource limits are listed below:

    ParameterRequiredDescription
    cpu_core_limitNoThe soft limit for the number of CPU cores that can be allocated to the resource group on the BE. In actual business scenarios, CPU cores that are allocated to the resource group proportionally scale based on the availability of CPU cores on the BE. Valid values: any non-zero positive integer.
    mem_limitNoThe percentage of memory that can be used for queries in the total memory that is provided by the BE. Unit: %. Valid values: (0, 1).
    concurrency_limitNoThe upper limit of concurrent queries in a resource group. It is used to avoid system overload caused by too many concurrent queries.
    max_cpu_coresNoThe CPU core limit for this resource group on a single BE node. It takes effect only when it is set to greater than 0. Range: [0, avg_be_cpu_cores], where avg_be_cpu_cores represents the average number of CPU cores across all BE nodes. Default: 0.
    big_query_cpu_second_limitNoThe upper time limit of CPU occupation for a big query. Concurrent queries add up the time. The unit is second.
    big_query_scan_rows_limitNoThe upper limit of row counts that can be scanned by a big query.
    big_query_mem_limitNoThe upper limit of memory usage of a big query. The unit is byte.
    typeNoThe type of resource group. Valid values:
    short_query: When queries from the short_query resource group are running, the BE node reserves the CPU cores defined in short_query.cpu_core_limit. CPU cores for all normal resource groups are limited to "the total CPU cores - short_query.cpu_core_limit".
    normal: When no query from the short_query resource group is running, the CPU core limit above is not imposed on the normal resource groups.
    Note that you can create only ONE short_query resource group in a cluster.

Example

Example 1: Creates the resource group rg1 based on multiple classifiers.

CREATE RESOURCE GROUP rg1
TO
(user='rg1_user1', role='rg1_role1', query_type in ('select'), source_ip='192.168.x.x/24'),
(user='rg1_user2', query_type in ('select'), source_ip='192.168.x.x/24'),
(user='rg1_user3', source_ip='192.168.x.x/24'),
(user='rg1_user4'),
(db='db1')
WITH ('cpu_core_limit' = '10',
'mem_limit' = '20%',
'type' = 'normal',
'big_query_cpu_second_limit' = '100',
'big_query_scan_rows_limit' = '100000',
'big_query_mem_limit' = '1073741824'
);