Aborting statements that take longer than a certain time to execute
MariaDB starting with 10.1.1
max_statement time
and the associated functionality was introduced in MariaDB 10.1.1
Contents
Overview
MariaDB 10.1.1 introduced the max_statement_time system variable. When set to a non-zero value, any queries taking longer than this time in seconds will be aborted. The default is zero, and no limits are then applied. The aborted query has no effect on any larger transaction or connection contexts.
The value can be set globally or per session, as well as per user or per query (see below).
An associated status variable, max_statement_time_exceeded, stores the number of queries that have exceeded the execution time specified by max_statement_time
.
The feature was based upon a patch by Davi Arnaut.
User max_statement_time
max_statement_time can be stored per user with the GRANT ... MAX_STATEMENT_TIME syntax.
max_statement_time per query
Individual queries can also be limited by adding a MAX_STATEMENT_TIME
clause to the query. For example:
SELECT MAX_STATEMENT_TIME=2 * FROM t1;
Differences between the MariaDB and MySQL implementations
MySQL 5.7.4 introduced similar functionality, but the MariaDB implementation differs in a number of ways.
- The MySQL version of max_statement_time is defined in millseconds, not seconds
- MySQL's implementation can only kill SELECTs, while MariaDB's can kill any queries (excluding stored procedures).
- MariaDB only introduced the max_statement_time_exceeded status variable, while MySQL also introduced a number of others which were not seen as necessary in MariaDB.