-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Feature Description
👋 Vitess,
Today it appears the query timeout functionality in vttablet query server (ie: --queryserver-config-query-timeout) kills slow running queries using a MySQL KILL <id> operation which I assume is done concurrently in another goroutine
Since (I believe) Oracle/Percona MySQL 5.6 the MAX_EXECUTION_TIME optimizer hint/comment was added to allow the MySQL server to kill a slow-running query at a specified number of milliseconds from within mysqld
This RFC is to propose/discuss a new query timeout behaviour where MAX_EXECUTION_TIME(milliseconds) is used to timeout a query at a certain time, instead of a KILL operation. This approach builds on an idea originally proposed by @demmer 🙇 .
To achieve this I believe this requires:
- A way to opt-in to this new behaviour, perhaps
--queryserver-config-query-timeout-method, options:vttablet(default for now) -vttabletrunsKILLin a new goroutine + connectionpushdown-vttabletlets MySQL handle query timeouts usingMAX_EXECUTION_TIMEoptimizer hints
- When enabled, rewriting the Vitess
QUERY_TIMEOUT_MSquery-directive to a MySQLSELECT /*+ MAX_EXECUTION_TIME(milliseconds) */optimizer-hint comment- Disabling the
KILLoperation when this feature is used
- Disabling the
- When no
QUERY_TIMEOUT_MSprovided, addMAX_EXECUTION_TIMEcomment with--queryserver-config-query-timeoutas the timeout - Ensuring the error returned from MySQL is compatible with the current one
- Use query-killed error to update
vttabletkill counter/stats - Real example:
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
- Use query-killed error to update
Thanks again @demmer for raising the idea this RFC is based on
Use Case(s)
This approach assumes that:
- It is more efficient for
mysqldto kill a query internally vs a remote/external operation - It is more efficient for
vttabletto add aMAX_EXECUTION_TIMEcomment vs perform aKILLoperation MAX_EXECUTION_TIMEis more reliable- Doesn't require an extra MySQL call (could fail)
- Does not depend on
vttablet(eg: a crash/restart)
These assumptions are theoretical and yet-to-be-proven