Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAX_EXECUTION_TIME behavior differences from MySQL #10955

Closed
morgo opened this issue Jun 26, 2019 · 5 comments · Fixed by #10963 or #10959
Closed

MAX_EXECUTION_TIME behavior differences from MySQL #10955

morgo opened this issue Jun 26, 2019 · 5 comments · Fixed by #10963 or #10959
Assignees
Labels
type/bug The issue is confirmed as a bug.

Comments

@morgo
Copy link
Contributor

morgo commented Jun 26, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?

MAX_EXECUTION_TIME was recently added in #7008
I noticed a few behavior differences from MySQL.

  1. What did you expect to see?

TiDB supports set max_execution_time=1000;, but does not support using this as a hint. This is important for languages such as Go, where connection pools (unless using a transaction) may share connections between gorountines. Thus, setting a session var is unreliable:

tidb> select /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(5);
+----------+
| SLEEP(5) |
+----------+
|        0 |
+----------+
1 row in set (5.00 sec)

mysql80> select /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(5);
+----------+
| SLEEP(5) |
+----------+
|        1 |
+----------+
1 row in set (1.00 sec)

The second issue is that when interrupting a sleep'ed query, MySQL will just have the sleep function return 1. TiDB instead returns an error:

tidb> set max_execution_time=100;
Query OK, 0 rows affected (0.00 sec)

tidb> SELECT SLEEP(10);
ERROR 1317 (70100): Query execution was interrupted

mysql80> set max_execution_time=100;
Query OK, 0 rows affected (0.00 sec)

mysql80> select sleep(10);
+-----------+
| sleep(10) |
+-----------+
|         1 |
+-----------+
1 row in set (0.10 sec)

A third issue is that the setting the global var did not work as expected:

morgo@ryzen:~/go/src/github.com/pingcap/tidb$ mysql -e 'set global max_execution_time=100'
morgo@ryzen:~/go/src/github.com/pingcap/tidb$ time mysql -e 'select sleep(10)'
+-----------+
| sleep(10) |
+-----------+
|         0 |
+-----------+

real    0m10.010s
user    0m0.005s
sys     0m0.000s

(Creating a new connection does show max_execution_time as 100, but this is not taking effect.)

A fourth issue is that the sleep function does not seem to cancel/interrupt. The query still runs for 60 seconds, even though it is only supposed to run for 100ms (this is different from 3rd issue, note the error message):

morgo@ryzen:~/go/src/github.com/pingcap/tidb$ time mysql -e 'set max_execution_time=100;select sleep(60)'
ERROR 1317 (70100) at line 1: Query execution was interrupted

real    1m0.010s
user    0m0.005s
sys     0m0.000s
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v3.0.0-rc.1-240-gcf5f42b8e
Git Commit Hash: cf5f42b8ece0fad2b3f93c6753747b392f33f4c8
Git Branch: master
UTC Build Time: 2019-06-26 03:16:26
GoVersion: go version go1.12.1 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false
1 row in set (0.00 sec)
@morgo
Copy link
Contributor Author

morgo commented Jun 26, 2019

@tiancaiamao PTAL

@morgo morgo added the type/bug The issue is confirmed as a bug. label Jun 26, 2019
@tiancaiamao
Copy link
Contributor

I'll take a look @morgo

@tiancaiamao
Copy link
Contributor

tiancaiamao commented Jun 27, 2019

This one fixes the "sleep" problem
#10959

tiancaiamao added a commit to tiancaiamao/tidb that referenced this issue Jun 27, 2019
…work

update go.mod to use the latest parser which fix the sql hint for MAX_EXECUTION_TIME
put max_execution_time into the auto load system variable list so it's correctly initialized
Fix issue pingcap#10955
@tiancaiamao
Copy link
Contributor

And this one fixes the SQL hint and set global var
#10963

@morgo
Copy link
Contributor Author

morgo commented Jun 28, 2019

I can still reproduce issues 2 and 4 (both should be fixed in #10959 ). I will add a "Fixes" in the issue description.

tidb> select /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(5);
ERROR 1317 (70100): Query execution was interrupted

mysql80> select /*+ MAX_EXECUTION_TIME(1000) */ SLEEP(5);
+----------+
| SLEEP(5) |
+----------+
|        1 |
+----------+
1 row in set (1.00 sec)

and:

time mysql -e 'set max_execution_time=100;select sleep(60)'
ERROR 1317 (70100) at line 1: Query execution was interrupted

real    1m0.010s
user    0m0.004s
sys     0m0.000s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
2 participants