Skip to content

Feature Request: support for MySQL MAX_EXECUTION_TIME for query timeout #12518

@timvaillancourt

Description

@timvaillancourt

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:

  1. A way to opt-in to this new behaviour, perhaps --queryserver-config-query-timeout-method, options:
    • vttablet (default for now) - vttablet runs KILL in a new goroutine + connection
    • pushdown - vttablet lets MySQL handle query timeouts using MAX_EXECUTION_TIME optimizer hints
  2. When enabled, rewriting the Vitess QUERY_TIMEOUT_MS query-directive to a MySQL SELECT /*+ MAX_EXECUTION_TIME(milliseconds) */ optimizer-hint comment
    • Disabling the KILL operation when this feature is used
  3. When no QUERY_TIMEOUT_MS provided, add MAX_EXECUTION_TIME comment with --queryserver-config-query-timeout as the timeout
  4. Ensuring the error returned from MySQL is compatible with the current one
    • Use query-killed error to update vttablet kill counter/stats
    • Real example: ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

Thanks again @demmer for raising the idea this RFC is based on

Use Case(s)

This approach assumes that:

  1. It is more efficient for mysqld to kill a query internally vs a remote/external operation
  2. It is more efficient for vttablet to add a MAX_EXECUTION_TIME comment vs perform a KILL operation
  3. MAX_EXECUTION_TIME is 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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions