Query execution was interrupted — timeout exceeded
ER_QUERY_TIMEOUT (3024) is returned in MySQL 8.0+ when a SELECT statement exceeds the max_execution_time hint or global setting. The query is killed and this error is returned.
SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM large_table WHERE unindexed_column = 'value'; -- Killed after 1000ms
expected output
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
Fix 1
Add an index and optimise the query
WHEN The query is doing a full table scan.
-- Check with EXPLAIN first: EXPLAIN SELECT * FROM large_table WHERE unindexed_column = 'value'; -- Add the index: ALTER TABLE large_table ADD INDEX idx_col (unindexed_column);
Why this works
An index reduces the query from a full-table scan to an index seek, dramatically reducing execution time.
Fix 2
Paginate large result sets
WHEN The query intentionally reads large amounts of data.
-- Use LIMIT with a cursor instead of fetching all rows: SELECT * FROM large_table WHERE id > :last_id ORDER BY id LIMIT 1000;
Why this works
Pagination limits the data processed per query, keeping execution time within acceptable bounds.
✕ Raise max_execution_time to suppress the error without fixing the query
Long-running queries hold locks and consume server resources; the timeout exists to protect other queries. Fix the query instead.
ER_QUERY_TIMEOUT (3024) replaces the informal timeout mechanism from earlier versions. The MAX_EXECUTION_TIME optimizer hint was added in MySQL 5.7.8.
MySQL 8.0 — 3024 ER_QUERY_TIMEOUT
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev