MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

The SELECT ran longer than the max_execution_time limit (session variable or optimizer hint) and was stopped.

MySQL 8.4.13
3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

Jump to a cause

  1. 01Session limit 1 second + correlated subquery on a column with no index
  2. 02MAX_EXECUTION_TIME hint in the query + DEPENDENT SUBQUERY

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

max_execution_time (milliseconds, 0 = no limit) and the /*+ MAX_EXECUTION_TIME(n) */ hint stop a SELECT that runs too long. When the limit is hit, MySQL ends the query with ERROR 3024 and returns no rows. Raising the limit hides the problem; both cases below made the query itself fast enough instead.

The tests used 2,000 customers and 100,000 orders on MySQL 8.4. This message stays in English even with Korean or Japanese lc_messages.

01Session limit 1 second + correlated subquery on a column with no index

With SET SESSION max_execution_time = 1000, a query summing each customer's orders in a subquery (WHERE o.customer_id = c.id) failed with ERROR 3024. information_schema.STATISTICS showed only PRIMARY, so every customer scanned all orders.

After CREATE INDEX idx_orders_customer ON orders (customer_id), the same query with the same 1-second limit returned 3 rows in 0.21 sec.

Setup
Setuprun as lab_a
SET SESSION cte_max_recursion_depth = 100000;
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(20));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, amount INT);
INSERT INTO customers WITH RECURSIVE r(v) AS (SELECT 1 UNION ALL SELECT v + 1 FROM r WHERE v < 2000) SELECT v, CONCAT('cust', v) FROM r;
INSERT INTO orders WITH RECURSIVE r(v) AS (SELECT 1 UNION ALL SELECT v + 1 FROM r WHERE v < 100000) SELECT v, v % 2000 + 1, v % 100 FROM r;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 2000 rows affected (0.02 sec)
Records: 2000  Duplicates: 0  Warnings: 0

Query OK, 100000 rows affected (0.31 sec)
Records: 100000  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SET SESSION max_execution_time = 1000;
SELECT c.id, c.name,
  (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id) AS total
FROM customers c ORDER BY total DESC, c.id LIMIT 3;
✕ ERROR
Query OK, 0 rows affected (0.00 sec)

ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
Checkrun as lab_a
SELECT INDEX_NAME, COLUMN_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = 'lab_a' AND TABLE_NAME = 'orders' ORDER BY INDEX_NAME;
OUTPUT
+------------+-------------+
| INDEX_NAME | COLUMN_NAME |
+------------+-------------+
| PRIMARY    | id          |
+------------+-------------+
1 row in set (0.00 sec)
Fixrun as lab_a
CREATE INDEX idx_orders_customer ON orders (customer_id);
OUTPUT
Query OK, 0 rows affected (0.15 sec)
Records: 0  Duplicates: 0  Warnings: 0

Check EXPLAIN for type ALL on the inner table of a subquery or join. An index on the join column is usually the fix.

After the fixrun as lab_a
SET SESSION max_execution_time = 1000;
SELECT c.id, c.name,
  (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id) AS total
FROM customers c ORDER BY total DESC, c.id LIMIT 3;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+------+---------+-------+
| id   | name    | total |
+------+---------+-------+
|  100 | cust100 |  4950 |
|  200 | cust200 |  4950 |
|  300 | cust300 |  4950 |
+------+---------+-------+
3 rows in set (0.21 sec)

02MAX_EXECUTION_TIME hint in the query + DEPENDENT SUBQUERY

The query itself had /*+ MAX_EXECUTION_TIME(1000) */, so the session setting did not matter; it failed with ERROR 3024. EXPLAIN showed DEPENDENT SUBQUERY on orders with type ALL and 100000 rows, run once per customer.

Without adding an index, the subquery was rewritten as LEFT JOIN orders ... GROUP BY c.id, c.name. With the same hint it returned the same 3 rows in 0.06 sec.

Setup
Setuprun as lab_a
SET SESSION cte_max_recursion_depth = 100000;
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(20));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, amount INT);
INSERT INTO customers WITH RECURSIVE r(v) AS (SELECT 1 UNION ALL SELECT v + 1 FROM r WHERE v < 2000) SELECT v, CONCAT('cust', v) FROM r;
INSERT INTO orders WITH RECURSIVE r(v) AS (SELECT 1 UNION ALL SELECT v + 1 FROM r WHERE v < 100000) SELECT v, v % 2000 + 1, v % 100 FROM r;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 2000 rows affected (0.02 sec)
Records: 2000  Duplicates: 0  Warnings: 0

Query OK, 100000 rows affected (0.31 sec)
Records: 100000  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT /*+ MAX_EXECUTION_TIME(1000) */ c.id, c.name,
  (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id) AS total
FROM customers c ORDER BY total DESC, c.id LIMIT 3;
✕ ERROR
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
Checkrun as lab_a
EXPLAIN SELECT /*+ MAX_EXECUTION_TIME(1000) */ c.id, c.name,
  (SELECT SUM(o.amount) FROM orders o WHERE o.customer_id = c.id) AS total
FROM customers c ORDER BY total DESC, c.id LIMIT 3;
OUTPUT
+----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+---------------------------------+
| id | select_type        | table | partitions | type | possible_keys | key  | key_len | ref  | rows   | filtered | Extra                           |
+----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+---------------------------------+
|  1 | PRIMARY            | c     | NULL       | ALL  | NULL          | NULL | NULL    | NULL |   2000 |   100.00 | Using temporary; Using filesort |
|  2 | DEPENDENT SUBQUERY | o     | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 100000 |    10.00 | Using where                     |
+----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+---------------------------------+
2 rows in set, 2 warnings (0.00 sec)
After the fixrun as lab_a
SELECT /*+ MAX_EXECUTION_TIME(1000) */ c.id, c.name, SUM(o.amount) AS total
FROM customers c LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.id, c.name ORDER BY total DESC, c.id LIMIT 3;
✓ SUCCESS
+-----+---------+-------+
| id  | name    | total |
+-----+---------+-------+
| 100 | cust100 |  4950 |
| 200 | cust200 |  4950 |
| 300 | cust300 |  4950 |
+-----+---------+-------+
3 rows in set (0.06 sec)

FAQ

How do I fix maximum statement execution time exceeded in MySQL?

Make the query faster: add an index on the join or WHERE column, or rewrite a per-row subquery as a JOIN with GROUP BY. Both were enough here without raising the limit.

Where does the limit come from?

From the max_execution_time variable (in milliseconds, 0 means no limit) or a /*+ MAX_EXECUTION_TIME(n) */ hint in the query. Check SELECT @@max_execution_time and the query text.

How do I find why the query is slow?

Run EXPLAIN on it. Here it showed DEPENDENT SUBQUERY on orders with type ALL and rows 100000: a full scan repeated for every customer.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13