pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.07k stars 5.83k forks source link

`ER_QUERY_TIMEOUT` error not returned when read query exceeding `max_execution_time` #56474

Closed anirudh-modi closed 1 week ago

anirudh-modi commented 1 week ago

Bug Report

I am using MySQL node js driver to connect to TiDb, I have set max_execution_time as 5seconds and when I running a select sleep (40) query, I am not getting any error.

1. Minimal reproduce step (Required)

  1. set max_execution_time = 5000
  2. Run SELECT 1, SLEEP(40)

2. What did you expect to see? (Required)

I expected to see an error like ER_QUERY_TIMEOUT

ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

3. What did you see instead (Required)

TiDb gave a warning and there was no error from the MYSQL library. TiDb Logs can be found below

2024-10-08 14:44:57 [2024/10/08 09:14:57.015 +00:00] [WARN] [expensivequery.go:96] ["execution timeout, kill it"] [costTime=5.090506377s] [maxExecutionTime=5s] [processInfo="{id:2097158, user:root, host::42425, db:anirudhlocal0001, command:Execute, time:5, state:autocommit, info:SELECT 1, SLEEP(40)}"]
2024-10-08 14:44:57 [2024/10/08 09:14:57.016 +00:00] [INFO] [server.go:895] [kill] [conn=2097158] [query=true]
2024-10-08 14:44:57 [2024/10/08 09:14:57.017 +00:00] [WARN] [sqlkiller.go:60] ["kill initiated"] ["connection ID"=2097158] [reason="[executor:3024]Query execution was interrupted, maximum statement execution time exceeded"]
2024-10-08 14:44:57 [2024/10/08 09:14:57.017 +00:00] [WARN] [sqlkiller.go:133] ["kill finished"] [conn=2097158]

4. What is your TiDB version? (Required)

Release Version: v8.2.0
Edition: Community
Git Commit Hash: 821e491a20fbab36604b36b647b5bae26a2c1418
Git Branch: HEAD
UTC Build Time: 2024-07-05 09:16:25
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Defined2014 commented 1 week ago

The result is same as MySQL v8.4 and v9.0, you could use return value of sleep function to verified it is killed or not.

See details https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_sleep

anirudh-modi commented 1 week ago

@Defined2014 Should not the select statement throw the error mentioned as there is a sleep statement which is taking more than max_execution_time?

Defined2014 commented 1 week ago

@Defined2014 Should not the select statement throw the error mentioned as there is a sleep statement which is taking more than max_execution_time?

Hi @anirudh-modi, You could read the MySQL docs.

When SLEEP() is only part of a query that is interrupted, the query returns an error: