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

expression: make sleep function response to the kill statement #10959

Merged
merged 4 commits into from
Jul 1, 2019

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jun 27, 2019

What problem does this PR solve?

Fixes #10955

Execute select sleep() in one session, and kill tidb query xxx in another session,
the sleep query is not interrupted.

mysql> select sleep(10);
+-----------+
| sleep(10) |
+-----------+
|         0 |
+-----------+
1 row in set (10.00 sec)

What is changed and how it works?

Check the Killed variable once in a while during the sleep function.

Check List

Tests

  • Unit test

  • Need to cherry-pick to the release branch

@codecov
Copy link

codecov bot commented Jun 27, 2019

Codecov Report

Merging #10959 into master will decrease coverage by 0.0038%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #10959        +/-   ##
================================================
- Coverage   80.8878%   80.8839%   -0.0039%     
================================================
  Files           418        418                
  Lines         89184      89187         +3     
================================================
- Hits          72139      72138         -1     
- Misses        11804      11806         +2     
- Partials       5241       5243         +2

@codecov
Copy link

codecov bot commented Jun 27, 2019

Codecov Report

Merging #10959 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #10959   +/-   ##
===========================================
  Coverage   81.0646%   81.0646%           
===========================================
  Files           418        418           
  Lines         89473      89473           
===========================================
  Hits          72531      72531           
  Misses        11716      11716           
  Partials       5226       5226

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

/run-unit-test

@tiancaiamao
Copy link
Contributor Author

PTAL @jackysp @XuHuaiyu

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, period check maybe look good for current code - -

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==

@lysu
Copy link
Contributor

lysu commented Jun 28, 2019

@tiancaiamao I think I found a bug 🤔

In MySQL:

select /*+ MAX_EXECUTION_TIME(1000) */ sleep(4), (select sleep(5));
+----------+-------------------+
| sleep(4) | (select sleep(5)) |
+----------+-------------------+
|        1 |                 1 |
+----------+-------------------+
1 row in set (1.00 sec)

but in TiDB:

mysql> select /*+ MAX_EXECUTION_TIME(1000) */ sleep(4), (select sleep(5));
+----------+-------------------+
| sleep(4) | (select sleep(5)) |
+----------+-------------------+
|        1 |                 0 |
+----------+-------------------+
1 row in set (6.09 sec)

it seems we only can kill one operator, but if later operators have time-wasted task, the query cannot return immediately

@tiancaiamao
Copy link
Contributor Author

@lysu Good job, you find a bug! But this is not true:

it seems we only can kill one operator, but if later operators have time-wasted task, the query cannot return immediately

The real problem is that MAX_EXECUTION_TIME hint can only kill query in execute phase, while in your given query, sleep happens plan build phase.

To verify that, you can try this, this takes 5s:

mysql> explain select /*+ MAX_EXECUTION_TIME(1000) */ 1,  (select sleep(5));
+--------------------+-------+------+---------------+
| id                 | count | task | operator info |
+--------------------+-------+------+---------------+
| Projection_9       | 1.00  | root | 1, 0          |
| └─TableDual_10     | 1.00  | root | rows:1        |
+--------------------+-------+------+---------------+
2 rows in set (5.00 sec)

As a contrast, this query returns immediately:

mysql> explain select /*+ MAX_EXECUTION_TIME(1000) */ 1,  sleep(5);
+-------------------+-------+------+---------------+
| id                | count | task | operator info |
+-------------------+-------+------+---------------+
| Projection_3      | 1.00  | root | 1, sleep(5)   |
| └─TableDual_4     | 1.00  | root | rows:1        |
+-------------------+-------+------+---------------+
2 rows in set (0.01 sec)

When there is a sleep in (select sleep(5)), we'll execute the subquery, this happens in the plan building phase and can not be canceled by MAX_EXECUTION_TIME

@tiancaiamao
Copy link
Contributor Author

I think we can file an issue, and merge this PR first.

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lysu lysu added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 1, 2019
@tiancaiamao
Copy link
Contributor Author

PTAL @lysu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MAX_EXECUTION_TIME behavior differences from MySQL
3 participants