-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
We are currently using a maximum execution time query hint (/*+ MAX_EXECUTION_TIME(1000) */
) to limit the execution time of some queries.
It turned out that this query hint does not work as expected when using MySQLI. The test for this currently always fails with MySQLI. Using PDO/MySQL it works correctly.
This seems to be a general issue with prepared statements and mysqli. Tried to test that directly by using the native mysqli methods, which Zend Framework should also do somewhere in the code.
MYSQLI Query
$mysqli = new mysqli("localhost", "matomo", "matomo", "matomo");
$mysqli->query("SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(5) FROM matomo_log_visit");
This results as expected in
PHP Warning: mysqli::query(): (HY000/3024): Query execution was interrupted, maximum statement execution time exceeded in /srv/matomo/mysqli.php on line 6
MYSQLI Prepared Statement
$mysqli = new mysqli("localhost", "matomo", "matomo", "matomo");
$stmt = $mysqli->prepare("SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(5) FROM matomo_log_visit");
$stmt->execute();
This runs through without any issues. Fetching the result of the query returns 1
, which is the result of the SLEEP method. So it seems the query hint is ignored.
MYSQL Prepared Statement
Running a prepared statement directly in mysql console like this:
PREPARE stmt FROM 'SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(5) FROM matomo_log_visit';
EXECUTE stmt;
results in SQL ERROR (3024): Query execution was interrupted, maximum statement execution time exceeded
So query hints in prepared statements generally should work.
Conclusion
Guess query hints is something that can't work with the Zend MYSQLI adapter as it seems to use prepared statements always.
We need to decide how to go on with this. Tried to find (bug) reports or questions on that topic, but wasn't able to find anything. Not sure if that is a bug in the MYSQLI extension for PHP or something else.