Workload management (WLM) rules control query behavior in AnalyticDB for MySQL Data Warehouse Edition clusters. You can define rules based on query properties—such as user, source IP, query type, or historical execution patterns—and specify actions such as ending queries, adjusting priority, or rerouting queries to different resource groups.
Prerequisites
Make sure you have:
-
An AnalyticDB for MySQL Data Warehouse Edition cluster
-
A cluster minor version of 3.1.6.3 or later
To check or update your minor version, see Update the minor version of a cluster.
Usage notes
-
Modifying rules with WLM syntax requires cluster version V3.1.10.0 or later.
-
AnalyticDB for MySQL uses a soft delete policy for rules. New rules cannot reuse names of previously deleted rules.
Create a rule
Syntax
wlm add_rule
name=<rule_name>
type=query
action=<action>
predicate='<property><operator><value> && <property><operator><value>'
[attrs='<rule_attrs>']
[resource_group=<resource_group>]
[description='<description>']
[compatible_group=<compatible_group_name>]
[enabled=<true|false>]
[priority=<priority>]
No spaces are allowed on either side of the equal sign (=).
Parameters
|
Parameter |
Required |
Description |
|
|
Yes |
Rule name. Must be unique among all existing and deleted rules. |
|
|
Yes |
Rule type. Set to |
|
|
Yes |
Action to perform when a query matches. See Actions. |
|
|
Yes |
Match conditions joined by |
|
|
No |
Action attributes. Required when |
|
|
No |
Resource group name. Default: |
|
|
No |
Rule description. Enclose in single quotes. |
|
|
No |
Compatibility group name. Rules in the same group are all evaluated when any one matches, regardless of priority order. |
|
|
No |
Whether the rule is active. Values: |
|
|
No |
Rule priority. Default: |
In predicate values, add spaces on both sides of the in operator only. Do not add spaces around other operators.
Examples
End queries by user and pattern latency
End queries from user test where the P50 historical execution duration exceeds 60,000 ms:
wlm add_rule
name=testRule1
type=query
action=kill
predicate='user=test && PATTERN_RT_P50>60000';+---------------------------------+
| result |
+---------------------------------+
| insert rule 'testRule1' success |
+---------------------------------+
Add query priority hints by user and IP
Lower the priority of queries from user test originating from specific IP addresses:
wlm add_rule
name=testRule2
type=query
action=ADD_PROPERTIES
attrs='{"add_prop":{"query_priority":"low"}}'
predicate='user=test && source_ip in 10.10.10.10,192.168.0.1,192.0.2.1';+---------------------------------+
| result |
+---------------------------------+
| insert rule 'testRule2' success |
+---------------------------------+
End SELECT queries for a specific resource group
Create a priority-5 rule for testResourceGroup that ends SELECT queries from user test:
wlm add_rule
name=testRule3
type=query
resource_group=testResourceGroup
description='just a test'
priority=5
action=kill
predicate='user=test && query_task_type=1';+---------------------------------+
| result |
+---------------------------------+
| insert rule 'testRule3' success |
+---------------------------------+
Modify a rule
Modifying rules requires cluster version V3.1.10.0 or later. To check your version, see How do I view the minor version of a cluster?. To update the version, contact technical support.
Syntax
wlm update_rule
id=<rule_id>
name=<rule_name>
type=query
action=<action>
predicate='<property><operator><value> && <property><operator><value>'
[attrs='<rule_attrs>']
[resource_group=<resource_group>]
[description='<description>']
[compatible_group=<compatible_group_name>]
[enabled=<true|false>]
[priority=<priority>]
No spaces are allowed on either side of the equal sign (=).
Parameters
All parameters are optional for update_rule. Specify id or name to identify the target rule.
|
Parameter |
Description |
|
|
Rule ID (unique, immutable). Run |
|
|
Rule name. To rename a rule, specify the rule by |
|
|
Rule type. Set to |
|
|
Action to perform. See Actions. |
|
|
Updated match conditions. See Properties and Operators. |
|
|
Updated action attributes. Required when |
|
|
Resource group name. Default: |
|
|
Rule description. |
|
|
Compatibility group name. |
|
|
|
|
|
Rule priority. Default: |
Examples
Rename a rule
wlm update_rule
id=2
name=Rule;+-----------------+
| result |
+-----------------+
| update rule 2 |
+-----------------+
Update predicate conditions
Change the P50 latency threshold of testRule1 from 60,000 ms to 80,000 ms:
wlm update_rule
name=testRule1
predicate='user=test && PATTERN_RT_P50>80000';
Or use the rule ID:
wlm update_rule
id=1
predicate='user=test && PATTERN_RT_P50>80000';+-----------------+
| result |
+-----------------+
| update rule 1 |
+-----------------+
Change a KILL action to RESUBMIT_RESOURCE_GROUP
Reroute matching queries to a different resource group instead of ending them:
wlm update_rule
name=testRule1
action=RESUBMIT_RESOURCE_GROUP
attrs='{
"resubmit":{
"resource_group": "testgroup"
}
}'
For attrs format details, see Actions.
+-----------------+
| result |
+-----------------+
| update rule 1 |
+-----------------+
List rules
Syntax
wlm list_rule
[id=<rule_id>]
[name='<rule_name>'\G]
Parameters
|
Parameter |
Required |
Description |
|
|
No |
Filter by rule ID. Omit |
|
|
No |
Filter by rule name. Enclose in single quotes. |
|
|
No |
Display each field on a separate line. |
Examples
List a rule by ID
wlm list_rule
id=1 \G;id: 1
name: testRule4
description: NULL
type: QUERY
resource_group: user_default
enabled: 1
priority: 0
version: 1
life_cycle: BEFORE_QUEUEING
compatible_group:
valid_begin: null
valid_end: null
creator: kepler
update_user: kepler
create_time: 2022-09-16 14:00:18
update_time: 2022-09-16 14:00:18
predicate: [{"property":"${session.user}","value":"test","operator":"equal"},{"property":"${session.source_ip}","value":"1,2,3","operator":"in"}]
action: ADD_PROPERTIES
attrs: {"add_prop":{"query_priority":"low"}}
1 row in set (0.11 sec)
List a rule by ID and name
wlm list_rule
id=1
name='testRule4' \G;
Disable a rule
wlm disable_rule id=<rule_id>
Run wlm list_rule to find rule IDs.
Example
wlm disable_rule id=1;+------------------+
| result |
+------------------+
| disable rule 1 |
+------------------+
Verify that the rule is disabled (enabled: 0):
wlm list_rule id=1\G;
Enable a rule
wlm enable_rule id=<rule_id>
Run wlm list_rule to find rule IDs.
Example
wlm enable_rule id=1;+----------------+
| result |
+----------------+
| enable rule 1 |
+----------------+
Verify that the rule is enabled (enabled: 1):
wlm list_rule id=1\G;
Delete a rule
wlm delete_rule id=<rule_id>
Run wlm list_rule to find rule IDs. Deleted rule names cannot be reused.
Example
wlm delete_rule id=1;+----------------+
| result |
+----------------+
| delete rule 1 |
+----------------+
Verify deletion:
wlm list_rule id=1\G;Empty set
Get the pattern hash of a query
Use calc_pattern_hash to get the hash value of an SQL pattern. You can then use this value with the pattern_hash property in predicates to target specific query patterns.
Syntax
wlm calc_pattern_hash <SQL>
The <SQL> parameter accepts a SELECT query or a write query that contains SELECT statements.
Example
wlm calc_pattern_hash select * from t where a=1 and b=2;+-----------------------------------+----------------------+
| raw_sql | pattern_hash |
+-----------------------------------+----------------------+
| select * from t where a=1 and b=2 | -4759960226441980963 |
+-----------------------------------+----------------------+
List all WLM commands
wlm;+---------------------------+-------------------------------------+
| command | description |
+---------------------------+-------------------------------------+
| calc_pattern_hash | calculate pattern_hash of query |
| add_rule | add a new rule |
| list_rule id=[x]|name=[x] | list all rules OR filter by id/name |
| disable_rule id=[x] | disable a rule by id |
| enable_rule id=[x] | enable a rule by id |
| delete_rule id=[x] | delete a rule by id |
| update_rule id=[x] | update a rule by id |
+---------------------------+-------------------------------------+
Reference
Properties
Properties specify which aspects of a query to evaluate in rule predicates.
Query properties
|
Property |
Data type |
Description |
|
|
String |
User who submitted the query. |
|
|
String |
Client IP address. |
|
|
Numeric |
Query type: |
|
|
String list |
Tables involved in the query. |
|
|
String list |
Databases involved in the query. |
|
|
Numeric |
Hash value of the SQL pattern. |
|
|
String |
Original SQL statement. Requires V3.1.8.3 or later. |
Runtime properties
Runtime properties evaluate queries based on current execution statistics.
|
Property |
Data type |
Unit |
Description |
|
|
Numeric |
ms |
Total CPU time consumed by all tasks. |
|
|
Numeric |
ms |
Execution duration, excluding queue time. |
|
|
Numeric |
- |
Submission timestamp. |
|
|
Numeric |
- |
Total tasks in the physical execution plan. |
|
|
Numeric |
MB |
Data read by the query. |
|
|
Numeric |
MB |
Data shuffled during execution. |
|
|
Numeric |
MB |
Data output by the query. |
|
|
Numeric |
MB |
Peak memory usage. |
|
|
Numeric |
- |
Total stages in the execution plan. |
Pattern properties
Pattern properties evaluate queries based on historical execution data for a given SQL pattern.
|
Property |
Data type |
Unit |
Description |
|
|
Numeric |
ms |
50th percentile execution duration. |
|
|
Numeric |
ms |
90th percentile execution duration. |
|
|
Numeric |
ms |
50th percentile execution duration, excluding queue time. |
|
|
Numeric |
ms |
90th percentile execution duration, excluding queue time. |
|
|
Numeric |
ms |
50th percentile wall time. |
|
|
Numeric |
ms |
90th percentile wall time. |
|
|
Numeric |
bytes |
Average shuffle data size. |
|
|
Numeric |
bytes |
Average peak memory usage. |
|
|
Numeric |
- |
Average number of input rows. |
|
|
Numeric |
- |
Average number of output rows. |
Operators
|
Operator |
Supported types |
Description |
|
|
Numeric |
Greater than. |
|
|
Numeric |
Less than. |
|
|
Numeric, String |
Equal to. |
|
|
Numeric |
Greater than or equal to. |
|
|
Numeric |
Less than or equal to. |
|
|
Numeric, String |
Not equal to. |
|
|
String list |
Checks whether two string lists intersect. Add spaces on both sides of this operator. |
|
|
String |
Checks whether a string contains another string. Use with the |
Actions
|
Action |
Description |
|
|
|
Ends the query. |
Not required. |
|
|
Stops execution in the current resource group and resubmits the query to a different resource group. |
|
|
|
Modifies query properties such as priority. |
|
|
|
Ends the query at a specified probability before it enters the queue. Use for throttling. |
|
ADD_PROPERTIES details:
-
query_priority: Set as an integer (0--39, higher is higher priority) or a string: For more information, see Priority queue and concurrency of interactive resource groups.String value
Numeric equivalent
LOWEST5
LOW15
NORMAL25
HIGH35
-
force: Whether to overwrite existing query properties. Values:true(default for V3.1.9.4 and later) orfalse(default for versions earlier than V3.1.9.4). See How do I view the minor version of a cluster?.
BLOCK_WITH_PROB details:
-
prob: Probability of ending the query. Valid values: 0 to 1.