Question Details

No question body available.

Tags

mysql

Answers (2)

Accepted Answer Available
Accepted Answer
June 21, 2025 Score: 3 Rep: 34,519 Quality: High Completeness: 70%

Sleep() indeed does not modify the database, but according to sleep() function's documentation, maxexecutiontime setting does apply to it and terminates it:

When SLEEP() is the only thing invoked by a query that is interrupted, it returns 1 and the query itself returns no error. This is true whether the query is killed or times out:

After this paragraph there are two code examples. The 2nd one demonstrates the effect of maxexecutiontime and shows sleep() returning after maxexecutiontime elapsing with the return value of 1.

So, please check the return value of sleep() function to determine if it returned earlier than its parameter would suggest.

June 21, 2025 Score: 0 Rep: 482 Quality: Low Completeness: 80%

Just for additional information purpose to @Shadow 's answer:

SET SESSION MAXEXECUTIONTIME = 5000; -- 5 s
SELECT SLEEP(1); -- return 0
SELECT SLEEP(10); -- return 1

I then tested what will happen if it's actual data from here:

SET SESSION MAXEXECUTIONTIME = 1; -- 1ms

SELECT SQLNOCACHE * FROM STUDYSQL.EMPLOYEES AS FIR LEFT JOIN STUDYSQL.EMPLOYEES AS SEC ON FIR.BIRTHDATE SEC.BIRTHDATE WHERE (FIR.LASTNAME LIKE 't%o%' OR FIR.LASTNAME LIKE 'b%i%') AND FIR.FIRSTNAME LIKE '%e%' AND (SEC.LASTNAME LIKE 't%o%' OR SEC.LASTNAME LIKE 'b%i%') AND SEC.FIRSTNAME LIKE '%e%' AND SEC.FIRSTNAME LIKE '%b%';

The result is:

15:54:46    SET SESSION MAXEXECUTION_TIME = 1  0 row(s) affected   0.000 sec

15:54:46 [complex query] LIMIT 0, 1000 Error Code: 3024. Query execution was interrupted, maximum statement execution time exceeded 0.000 sec

So it will throw an exception if it's an actual query and it exceeds the time limit.