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

parser: add nowait keyword, add for update no wait grammar, and related error… #582

Merged
merged 4 commits into from
Oct 18, 2019

Conversation

cfzjywxk
Copy link
Contributor

… code/msg

What problem does this PR solve?

support select for update nowait

# Session 1:

mysql> CREATE TABLE t (i INT, PRIMARY KEY (i)) ENGINE = InnoDB;

mysql> INSERT INTO t (i) VALUES(1),(2),(3);

mysql> START TRANSACTION;

mysql> SELECT * FROM t WHERE i = 2 FOR UPDATE;
+---+
| i |
+---+
| 2 |
+---+

# Session 2:

mysql> START TRANSACTION;

mysql> SELECT * FROM t WHERE i = 2 FOR UPDATE NOWAIT;
ERROR 3572 (HY000): Statement aborted because lock(s) could not be acquired immediately and NOW

What is changed and how it works?

Check List

Tests

  • Unit test

Code changes

  • Has exported variable/fields change

Side effects

Related changes

  • Need to update the documentation

@codecov
Copy link

codecov bot commented Oct 17, 2019

Codecov Report

Merging #582 into master will increase coverage by <.01%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #582      +/-   ##
==========================================
+ Coverage   71.82%   71.83%   +<.01%     
==========================================
  Files          32       32              
  Lines        7834     7836       +2     
==========================================
+ Hits         5627     5629       +2     
  Misses       1676     1676              
  Partials      531      531
Impacted Files Coverage Δ
parser.go 70.37% <ø> (ø) ⬆️
misc.go 96.49% <ø> (ø) ⬆️
ast/util.go 75% <0%> (ø) ⬆️
ast/dml.go 73.92% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 448f044...59c18d8. Read the comment docs.

Copy link
Contributor

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

From the description in https://dev.mysql.com/doc/refman/8.0/en/select.html#idm140006656103232, it's more appropriate to make NOWAIT its own modifier rather than grouping FOR UPDATE NOWAIT as a whole thing.

    [FOR {UPDATE | SHARE} [OF tbl_name [, tbl_name] ...] [NOWAIT | SKIP LOCKED] 
      | LOCK IN SHARE MODE]]

@coocood
Copy link
Member

coocood commented Oct 17, 2019

NOWAIT is an unreserved keyword, we need to add it to UnReservedKeyword: section in the parser.y.

@cfzjywxk
Copy link
Contributor Author

From the description in https://dev.mysql.com/doc/refman/8.0/en/select.html#idm140006656103232, it's more appropriate to make NOWAIT its own modifier rather than grouping FOR UPDATE NOWAIT as a whole thing.

    [FOR {UPDATE | SHARE} [OF tbl_name [, tbl_name] ...] [NOWAIT | SKIP LOCKED] 
      | LOCK IN SHARE MODE]]

we're currently groupint "FOR UPDATE" as a whole, and "SelectLockType" is defined as single int type, maybe we need to some refactorations on this for 8.0 compatibility ? There will be some other related work, do this refactoration in the future?
@coocood @kennytm

@coocood
Copy link
Member

coocood commented Oct 17, 2019

LGTM

@cfzjywxk cfzjywxk requested a review from kennytm October 18, 2019 04:43
@cfzjywxk
Copy link
Contributor Author

@jackysp @tiancaiamao PTAL

@kennytm
Copy link
Contributor

kennytm commented Oct 18, 2019

we're currently groupint "FOR UPDATE" as a whole, and "SelectLockType" is defined as single int type, maybe we need to some refactorations on this for 8.0 compatibility ? There will be some other related work, do this refactoration in the future?

@cfzjywxk IMO it's better to turn SelectLockType into a struct now, or add a new member to SelectStmt indicating whether it is NOWAIT (and SKIP LOCKED in the future).

To support SelectLockForUpdateNoWait you'll need to modify TiDB once now, and later when you refactor for 8.0 compatibility you'll need to modify the code again. So I think it's better to choose a solution which we know is going to last.

@coocood
Copy link
Member

coocood commented Oct 18, 2019

@kennytm
We can modify the code again later when we need to.
It's not certain if we need to support those features.

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

@coocood coocood merged commit 7bd38fd into pingcap:master Oct 18, 2019
@cfzjywxk cfzjywxk deleted the nowait branch October 18, 2019 07:13
tiancaiamao pushed a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
lyonzhi pushed a commit to lyonzhi/parser that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants