Home >Database >Mysql Tutorial >How Can I Limit the Execution Time of MySQL Queries?

How Can I Limit the Execution Time of MySQL Queries?

Susan Sarandon
Susan SarandonOriginal
2025-01-05 03:33:40347browse

How Can I Limit the Execution Time of MySQL Queries?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn