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

Projects
None yet
3 participants
@tiancaiamao
Copy link
Contributor

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor Author

commented Jun 27, 2019

/run-all-tests

@tiancaiamao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 28, 2019

/run-all-tests

@tiancaiamao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 28, 2019

/run-unit-test

@tiancaiamao

This comment has been minimized.

Copy link
Contributor Author

commented Jun 28, 2019

@jackysp
Copy link
Member

left a comment

LGTM

@lysu

lysu approved these changes Jun 28, 2019

Copy link
Member

left a comment

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

@lysu
Copy link
Member

left a comment

==

@lysu

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

@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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

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

@lysu

lysu approved these changes Jul 1, 2019

Copy link
Member

left a comment

LGTM

@lysu lysu added the status/LGT2 label Jul 1, 2019

@tiancaiamao

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

PTAL @lysu

@tiancaiamao tiancaiamao merged commit 7a6777d into pingcap:master Jul 1, 2019

6 checks passed

ci/circleci Your tests passed on CircleCI!
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/build_check_race Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev_2 Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@tiancaiamao tiancaiamao deleted the tiancaiamao:kill-sleep branch Jul 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.