All Products
Search
Document Center

ApsaraDB RDS:SQL throttling

Last Updated:Mar 28, 2026

A sudden surge of expensive SELECT statements can saturate CPU and I/O, causing cascading failures across all workloads. ApsaraDB RDS for MySQL includes a concurrency control (CCL) feature — implemented through AliSQL and the DBMS_CCL package — that lets you cap the number of concurrently running SQL statements by type. When the cap is reached, excess statements queue rather than execute, isolating problem query patterns so higher-priority workloads continue running normally.

Prerequisites

Before you begin, ensure that your instance meets one of the following version requirements:

  • MySQL 8.0 with minor version 20190816 or later

  • MySQL 5.7 with minor version 20200630 or later

How CCL works

CCL rules are stored in a system table named concurrency_control. AliSQL loads these rules into memory at startup and evaluates each incoming SQL statement against them.

Each rule targets SQL statements along one or more of the following dimensions:

  • SQL command — The statement type: SELECT, UPDATE, INSERT, or DELETE.

  • Object — The object that the SQL command operates on, such as a TABLE or VIEW.

  • Keywords — Words that must appear in the statement text.

  • Template — A normalized SQL pattern (digest), matched using STATEMENT_DIGEST_TEXT.

When a statement matches a rule and the concurrency limit is reached, the statement enters the Concurrency control waiting state. It resumes execution when a running statement completes and the count drops below the limit.

Rule priority

Each SQL statement matches at most one rule. When multiple rules could apply, AliSQL uses the following priority order (highest to lowest):

  1. Template rule

  2. Complete rule (SQL command + schema + table)

  3. Keyword rule

  4. SQL statement rule

Usage notes

  • CCL rules affect only the current instance. Because no binary log entries are generated, rule changes on the primary instance are not propagated to standby instances, read-only instances, or disaster recovery instances.

  • CCL includes a timeout mechanism to prevent deadlocks caused by DML statements. Threads waiting under a CCL rule also respond to transaction timeouts and thread termination.

Parameters

Configure the following parameters to control queue behavior:

ParameterDefaultDescription
ccl_max_waiting_count0 (no limit)Maximum number of statements that can queue simultaneously under a single CCL rule. When this limit is exceeded, the statement fails immediately with ERROR 7534 (HY000): Concurrency control waiting count exceed max waiting count.
ccl_wait_timeout86,400 secondsMaximum time a statement can wait in the queue. When this timeout is reached, the statement proceeds to execute and is no longer subject to the rule.

The concurrency_control system table

AliSQL automatically creates the concurrency_control table in the mysql tablespace when the instance starts. The table schema is:

CREATE TABLE `concurrency_control` (
  `Id` bigint NOT NULL AUTO_INCREMENT,
  `Type` enum('SELECT','UPDATE','INSERT','DELETE','TEMPLATE') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'SELECT',
  `Schema_name` varchar(64) COLLATE utf8mb3_bin DEFAULT NULL,
  `Table_name` varchar(64) COLLATE utf8mb3_bin DEFAULT NULL,
  `Concurrency_count` bigint NOT NULL,
  `Keywords` text COLLATE utf8mb3_bin,
  `State` enum('N','Y') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'Y',
  `Ordered` enum('N','Y') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N',
  `Digest` varchar(64) COLLATE utf8mb3_bin DEFAULT NULL,
  `SQL_template` longtext COLLATE utf8mb3_bin,
  PRIMARY KEY (`Id`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0 COMMENT='Concurrency control'

The following table describes the columns:

ColumnDescription
IdAuto-incremented rule ID.
TypeSQL command type. Valid values: SELECT, UPDATE, INSERT, DELETE, TEMPLATE. Default: SELECT.
Schema_nameDatabase name filter. Leave blank to match all databases.
Table_nameTable name filter. Leave blank to match all tables.
Concurrency_countMaximum concurrency allowed by this rule. Set to 0 to reject all matching statements immediately with ERROR 7535 (HY000): Concurrency control refuse to execute query.
KeywordsKeywords that must appear in the statement text. Separate multiple keywords with semicolons (;).
StateWhether the rule is active. Y = enabled, N = disabled. Default: Y.
OrderedWhether multiple keywords must match in sequence. Y = ordered, N = any order. Default: N.
Digest64-character hash derived from SQL_template, used for template matching.
SQL_templateThe normalized SQL template for template-based rules.

Manage CCL rules

Use the DBMS_CCL stored procedures to add, delete, view, and apply CCL rules without editing the concurrency_control table directly.

Add a rule

Syntax:

dbms_ccl.add_ccl_rule('<Type>','<Schema_name>','<Table_name>',<Concurrency_count>,'<Keywords>');

Examples:

Limit all SELECT statements to a concurrency of 10:

mysql> call dbms_ccl.add_ccl_rule('SELECT', '', '', 10, '');

Limit SELECT statements containing the keyword key1 to a concurrency of 20:

mysql> call dbms_ccl.add_ccl_rule('SELECT', '', '', 20, 'key1');

Limit SELECT statements on the test.t table containing key2 to a concurrency of 20:

mysql> call dbms_ccl.add_ccl_rule('SELECT', 'test', 't', 20, 'key2');

Add a template-based rule

Template-based rules match statements by their normalized SQL pattern. This lets you throttle a specific query shape across any parameter values.

Additional prerequisites:

  • MySQL 8.0 with minor version 20230630 or later

  • MySQL 5.7 with minor version 20241231 or later

Syntax:

dbms_ccl.add_ccl_rule('<Type>','<Schema_name>','<Table_name>',<Concurrency_count>,'', 'Template_sql');
Leave Table_name blank. Provide a single example SQL statement for Template_sql — AliSQL extracts the normalized template from it automatically. To preview the template for any statement, run SELECT STATEMENT_DIGEST_TEXT('<your_sql>').

Example:

Limit SELECT statements in the test database that match the pattern SELECT c FROM t1 WHERE id=? to a concurrency of 30:

call dbms_ccl.add_ccl_rule('TEMPLATE', 'test', '', 30, '', 'SELECT c FROM t1 WHERE id=4');

Delete a rule

Syntax:

dbms_ccl.del_ccl_rule(<Id>);

Example:

Delete the rule with ID 15:

mysql> call dbms_ccl.del_ccl_rule(15);

If the rule does not exist, the system returns warnings instead of an error. Run SHOW WARNINGS to see details:

mysql> call dbms_ccl.del_ccl_rule(100);
  Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------+
| Level   | Code | Message                                            |
+---------+------+----------------------------------------------------+
| Warning | 7514 | Concurrency control rule 100 is not found in table |
| Warning | 7514 | Concurrency control rule 100 is not found in cache |
+---------+------+----------------------------------------------------+

View active rules

Syntax:

dbms_ccl.show_ccl_rule();

Example:

mysql> call dbms_ccl.show_ccl_rule();
+------+--------+--------+-------+-------+-------+-------------------+---------+---------+----------+----------+
| ID   | TYPE   | SCHEMA | TABLE | STATE | ORDER | CONCURRENCY_COUNT | MATCHED | RUNNING | WAITTING | KEYWORDS |
+------+--------+--------+-------+-------+-------+-------------------+---------+---------+----------+----------+
|   17 | SELECT | test   | t     | Y     | N     |                30 |       0 |       0 |        0 |          |
|   16 | SELECT |        |       | Y     | N     |                20 |       0 |       0 |        0 | key1     |
|   18 | SELECT |        |       | Y     | N     |                10 |       0 |       0 |        0 |          |
+------+--------+--------+-------+-------+-------+-------------------+---------+---------+----------+----------+

The output includes the following runtime counters:

ColumnDescription
MATCHEDNumber of times this rule has been matched since the instance started.
RUNNINGNumber of threads currently executing under this rule.
WAITTINGNumber of threads currently queued under this rule.

Apply direct table edits

If you modify rules directly in the concurrency_control table, the changes do not take effect until you flush them into memory:

Syntax:

dbms_ccl.flush_ccl_rule();

Example:

Update the concurrency count for rule 18, then apply the change:

mysql> update mysql.concurrency_control set CONCURRENCY_COUNT = 15 where Id = 18;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> call dbms_ccl.flush_ccl_rule();
Query OK, 0 rows affected (0.00 sec)
Use add_ccl_rule and del_ccl_rule for routine rule management. Use flush_ccl_rule only when you need to make bulk edits directly in the table.

Test CCL rules

The following example shows how to verify that CCL rules enforce concurrency limits as expected.

Rules:

-- Limit concurrent SELECT statements on test.sbtest1 to 3.
call dbms_ccl.add_ccl_rule('SELECT', 'test', 'sbtest1', 3, '');

-- Limit concurrent SELECT statements containing "sbtest2" to 2.
call dbms_ccl.add_ccl_rule('SELECT', '', '', 2, 'sbtest2');

-- Limit all concurrent SELECT statements to 2.
call dbms_ccl.add_ccl_rule('SELECT', '', '', 2, '');

Test conditions: Sysbench with 64 threads, 4 tables, select.lua.

Results:

mysql> call dbms_ccl.show_ccl_rule();
+------+--------+--------+---------+-------+-------+-------------------+---------+---------+----------+----------+
| ID   | TYPE   | SCHEMA | TABLE   | STATE | ORDER | CONCURRENCY_COUNT | MATCHED | RUNNING | WAITTING | KEYWORDS |
+------+--------+--------+---------+-------+-------+-------------------+---------+---------+----------+----------+
|   20 | SELECT | test   | sbtest1 | Y     | N     |                 3 |     389 |       3 |        9 |          |
|   21 | SELECT |        |         | Y     | N     |                 2 |     375 |       2 |       14 | sbtest2  |
|   22 | SELECT |        |         | Y     | N     |                 2 |     519 |       2 |       34 |          |
+------+--------+--------+---------+-------+-------+-------------------+---------+---------+----------+----------+
3 rows in set (0.00 sec)

The RUNNING values match the concurrency limits defined in each rule, confirming that CCL is enforcing the caps correctly.

Error reference

ErrorWhen it occursWhat to do
ERROR 7534 (HY000): Concurrency control waiting count exceed max waiting countThe number of queued statements exceeded ccl_max_waiting_count.Increase ccl_max_waiting_count, raise Concurrency_count on the rule, or optimize the queries triggering the rule.
ERROR 7535 (HY000): Concurrency control refuse to execute queryA rule has Concurrency_count = 0, which rejects all matching statements immediately.Update the rule to a non-zero concurrency count, or delete the rule.
Warning 7514: Concurrency control rule <id> is not founddel_ccl_rule was called with an ID that does not exist in the table or in memory.Run show_ccl_rule() to list active rule IDs before deleting.
When CCL rejects or queues a statement, your application receives one of the errors above. Add error handling in your application code — for example, retry logic for queued statements that time out (ERROR 7534), and circuit-breaker or fallback behavior for statements rejected by a zero-concurrency rule (ERROR 7535).