Limiting Query Execution Time in MySQL
To ensure efficient query execution, it may be necessary to enforce a maximum execution time for SQL queries, similar to the set_time_limit() functionality in PHP.
Solution: Execution Time Limit in MySQL
Starting with MySQL 5.7.4, the MAX_EXECUTION_TIME() hint was introduced to limit the execution time of top-level read-only SELECT statements. This hint specifies the maximum execution time in milliseconds:
SELECT /*+ MAX_EXECUTION_TIME(1000) */ --in milliseconds * FROM table;
Implementation Note:
This feature is only applicable to read-only SELECT statements. It was initially named MAX_EXECUTION_TIME() in MySQL 5.7.4 and was renamed to max_execution_time in MySQL 5.7.8
The above is the detailed content of How Can I Limit the Execution Time of MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!