Skip to content

Commit

Permalink
parser: add nowait keyword, add for update no wait grammar, and relat…
Browse files Browse the repository at this point in the history
…ed error… (pingcap#582)
  • Loading branch information
cfzjywxk authored and coocood committed Oct 18, 2019
1 parent d8d367a commit daa9991
Show file tree
Hide file tree
Showing 8 changed files with 6,989 additions and 6,965 deletions.
5 changes: 4 additions & 1 deletion ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ const (
SelectLockNone SelectLockType = iota
SelectLockForUpdate
SelectLockInShareMode
SelectLockForUpdateNoWait
)

// String implements fmt.Stringer.
Expand All @@ -432,6 +433,8 @@ func (slt SelectLockType) String() string {
return "for update"
case SelectLockInShareMode:
return "in share mode"
case SelectLockForUpdateNoWait:
return "for update nowait"
}
return "unsupported select lock type"
}
Expand Down Expand Up @@ -881,7 +884,7 @@ func (n *SelectStmt) Restore(ctx *RestoreCtx) error {
case SelectLockInShareMode:
ctx.WriteKeyWord(" LOCK ")
ctx.WriteKeyWord(n.LockTp.String())
case SelectLockForUpdate:
case SelectLockForUpdate, SelectLockForUpdateNoWait:
ctx.WritePlain(" ")
ctx.WriteKeyWord(n.LockTp.String())
}
Expand Down
2 changes: 1 addition & 1 deletion ast/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package ast
func IsReadOnly(node Node) bool {
switch st := node.(type) {
case *SelectStmt:
if st.LockTp == SelectLockForUpdate {
if st.LockTp == SelectLockForUpdate || st.LockTp == SelectLockForUpdateNoWait {
return false
}

Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ var tokenMap = map[string]int{
"BINDINGS": bindings,
"EXPR_PUSHDOWN_BLACKLIST": exprPushdownBlacklist,
"OPT_RULE_BLACKLIST": optRuleBlacklist,
"NOWAIT": nowait,
}

// See https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html for details
Expand Down
2 changes: 1 addition & 1 deletion model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (*testModelSuite) TestModelBasic(c *C) {
c.Assert(tp.String(), Equals, "BTREE")
tp = IndexTypeHash
c.Assert(tp.String(), Equals, "HASH")
tp = 1E5
tp = 1e5
c.Assert(tp.String(), Equals, "")
has := index.HasPrefixIndex()
c.Assert(has, Equals, true)
Expand Down
1 change: 1 addition & 0 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ const (
ErrBadUser = 3162
ErrInvalidEncryptionOption = 3184
ErrRoleNotGranted = 3530
ErrLockAcquireFailAndNoWaitSet = 3572
ErrWindowNoSuchWindow = 3579
ErrWindowCircularityInWindowGraph = 3580
ErrWindowNoChildPartitioning = 3581
Expand Down
1 change: 1 addition & 0 deletions mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ var MySQLErrName = map[uint16]string{
ErrWindowFunctionIgnoresFrame: "Window function '%s' ignores the frame clause of window '%s' and aggregates over the whole partition",
ErrRoleNotGranted: "%s is is not granted to %s",
ErrMaxExecTimeExceeded: "Query execution was interrupted, max_execution_time exceeded.",
ErrLockAcquireFailAndNoWaitSet: "Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.",

// MariaDB errors.
ErrOnlyOneDefaultPartionAllowed: "Only one DEFAULT partition allowed",
Expand Down
Loading

0 comments on commit daa9991

Please sign in to comment.