Workload management (WLM) lets you control query load before queries run, while they run, and on an ongoing basis for specific tables or databases. Use the rules in this guide to prevent a few heavy queries from degrading cluster health for all users.
Use the following table to choose a strategy based on your current situation:
| Situation | Strategy |
|---|---|
| A known query pattern is too slow or too expensive to run at full concurrency | Throttle before execution — assign it to a low-priority queue |
| The cluster is already under critical load | Stop during execution — stop specific query types, users, or IP addresses immediately |
| Certain tables or databases consistently cause pressure | Routine throttling — permanently assign queries against those objects to a lower-priority queue |
Prerequisites
Before you begin, ensure that:
Your AnalyticDB for MySQL cluster is running kernel version 3.1.6.3 or later
To check the kernel version, log on to the AnalyticDB for MySQL console and go to the Configuration Information section of the Cluster Information page. To upgrade, see Update the minor version of a cluster.
Before execution: throttle queries
Before a query runs, WLM evaluates it against your rules, assigns it to a queue, and enforces the concurrency limit for that queue. The diagram below shows how priority queues work:
Throttle queries by SQL pattern
Use this approach when you can identify a specific query pattern that is too expensive to run at full concurrency. WLM matches queries by their SQL pattern hash, so structurally identical queries are grouped and throttled together regardless of their literal parameter values.
Calculate the hash value of the SQL pattern you want to throttle:
wlm calc_pattern_hashFor command details, see Calculate a pattern_hash value.
Create a rule that routes queries with that pattern hash to the low-priority queue:
wlm add_rule name=confine_query type=query action=ADD_PROPERTIES predicate='pattern_hash=XXXXXXXXXXXXXX' attrs='{ "add_prop": { "query_priority": "low" } }'Replace
XXXXXXXXXXXXXXwith the hash value from step 1.Set the maximum concurrency for the low-priority queue. The default is 20:
SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;NoteFor more information about how to modify the queue concurrency, see Priority queues and concurrency of an Interactive resource group.
Lower this value to apply stricter throttling.
Throttle queries based on historical execution time
Use this approach when you want to automatically catch slow queries without identifying specific patterns upfront. The predicate PATTERN_EXECUTION_TIME_P50>2000 matches queries whose historical median (P50) execution time for that SQL pattern exceeds 2,000 milliseconds — a reliable signal that the query is expensive at scale.
Create a rule that routes historically slow queries to the low-priority queue:
wlm add_rule name=confine_query type=query action=ADD_PROPERTIES predicate='PATTERN_EXECUTION_TIME_P50>2000' attrs='{ "add_prop": { "query_priority": "low" } }'Set the maximum concurrency for the low-priority queue:
SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;
During execution: stop abnormal queries
When the cluster is already under critical load, create a KILL rule to stop specific queries immediately. Because KILL rules affect all matching queries — including queries that start after the rule is created — delete or disable each rule as soon as the cluster load returns to normal. For instructions on deleting or disabling a rule, see WLM.
Stop all SELECT queries
Use this when SELECT queries are blocking critical writes and you need to stop them immediately. Setting query_task_type=1 targets SELECT queries only.
wlm add_rule
name=kill_select_query
type=query
action=KILL
predicate='query_task_type=1'This rule stops all active SELECT queries and continues to block new ones until you delete or disable it. Delete this rule as soon as the cluster load normalizes.
Stop queries from a specific user
Use this when queries from a single user account are causing cluster instability.
wlm add_rule
name=kill_query_from_user
type=query
action=KILL
predicate='user=testuser1'Replace testuser1 with the actual username. Delete this rule after the situation is resolved.
Stop queries from a specific IP address
Use this when you have traced the problematic queries to a single IP address.
wlm add_rule
name=kill_query_from_ip
type=query
action=KILL
predicate='source_ip=10.10.XX.XX'Replace 10.10.XX.XX with the actual IP address. Delete this rule after the situation is resolved.
Stop all queries exceeding 100 MB of memory
Use this when memory-intensive queries are destabilizing the cluster and you need to stop all of them, including write operations.
wlm add_rule
name=kill_Big_query
type=query
action=KILL
predicate='QUERY_PEAK_MEMORY>=100'This rule applies to both SELECT queries and write operations. Delete this rule after the cluster stabilizes.
Stop SELECT queries exceeding 100 MB of memory
Use this when large SELECT queries are causing instability but you want to keep write operations running. The predicate combines a memory threshold with query_task_type=1 to target only SELECT queries.
wlm add_rule
name=kill_Big_query
type=query
action=KILL
predicate='QUERY_PEAK_MEMORY>100 && query_task_type=1'Delete this rule after the cluster stabilizes.
Routine throttling
Use routine throttling to permanently limit the concurrency of queries that scan specific tables or databases — for example, tables used by low-priority reporting jobs that run alongside production workloads.
Create a rule that routes queries scanning the target tables to the low-priority queue:
wlm add_rule name=confine_query_in_table type=query action=ADD_PROPERTIES predicate='query_table_list in database.table1, database.table2' attrs='{ "add_prop": { "query_priority": "low" } }'Replace
database.table1, database.table2with the actual database and table names you want to throttle.Set the maximum concurrency for the low-priority queue:
SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;
Predicates reference
The following table lists the predicates used in this guide. For a complete list of supported predicates and their valid values, see WLM.
| Predicate | Description | Example value |
|---|---|---|
pattern_hash | Hash value of an SQL pattern. Queries with the same structural pattern share the same hash value. Use wlm calc_pattern_hash to calculate it. | XXXXXXXXXXXXXX |
PATTERN_EXECUTION_TIME_P50 | Historical median execution time (in milliseconds) for an SQL pattern. Use > to match patterns that are consistently slow. | 2000 |
query_task_type | Type of query task. Set to 1 to match SELECT queries only. | 1 |
user | Database username. Matches all queries submitted by the specified user. | testuser1 |
source_ip | Source IP address of the query. Matches all queries from the specified IP address. | 10.10.XX.XX |
QUERY_PEAK_MEMORY | Peak memory used by the query, in MB. Use >= or > to match memory-intensive queries. | 100 |
query_table_list | Tables scanned by the query. Use in with a comma-separated list of database.table pairs. | database.table1, database.table2 |
Related topics
To manage existing rules (view, modify, disable, or delete), see WLM.
To calculate the hash value of a SQL pattern, see Calculate a pattern_hash value.