Skip to content

Commit

Permalink
add new lock syntax for mysql8
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Carnahan <patrickcarnahan@github.com>
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
  • Loading branch information
patrickcarnahan authored and arthurschreiber committed Oct 10, 2023
1 parent 1fd96b4 commit 38eccb9
Show file tree
Hide file tree
Showing 7 changed files with 5,059 additions and 4,921 deletions.
10 changes: 10 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,16 @@ func (lock Lock) ToString() string {
return NoLockStr
case ForUpdateLock:
return ForUpdateStr
case ForUpdateLockNoWait:
return ForUpdateNoWaitStr
case ForUpdateLockSkipLocked:
return ForUpdateSkipLockedStr
case ForShareLock:
return ForShareStr
case ForShareLockNoWait:
return ForShareNoWaitStr
case ForShareLockSkipLocked:
return ForShareSkipLockedStr
case ShareModeLock:
return ShareModeStr
default:
Expand Down
16 changes: 13 additions & 3 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ const (
SQLCalcFoundRowsStr = "sql_calc_found_rows "

// Select.Lock
NoLockStr = ""
ForUpdateStr = " for update"
ShareModeStr = " lock in share mode"
NoLockStr = ""
ForUpdateStr = " for update"
ForUpdateNoWaitStr = " for update nowait"
ForUpdateSkipLockedStr = " for update skip locked"
ForShareStr = " for share"
ForShareNoWaitStr = " for share nowait"
ForShareSkipLockedStr = " for share skip locked"
ShareModeStr = " lock in share mode"

// Select.Cache
SQLCacheStr = "sql_cache "
Expand Down Expand Up @@ -466,6 +471,11 @@ const (
NoLock Lock = iota
ForUpdateLock
ShareModeLock
ForShareLock
ForShareLockNoWait
ForShareLockSkipLocked
ForUpdateLockNoWait
ForUpdateLockSkipLocked
)

// Constants for Enum Type - TrimType
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ var keywords = []keyword{
{"localtimestamp", LOCALTIMESTAMP},
{"locate", LOCATE},
{"lock", LOCK},
{"locked", LOCKED},
{"logs", LOGS},
{"long", UNUSED},
{"longblob", LONGBLOB},
Expand Down Expand Up @@ -448,6 +449,7 @@ var keywords = []keyword{
{"none", NONE},
{"not", NOT},
{"now", NOW},
{"nowait", NOWAIT},
{"no_write_to_binlog", NO_WRITE_TO_BINLOG},
{"nth_value", NTH_VALUE},
{"ntile", NTILE},
Expand Down Expand Up @@ -563,6 +565,7 @@ var keywords = []keyword{
{"signal", UNUSED},
{"signed", SIGNED},
{"simple", SIMPLE},
{"skip", SKIP},
{"slow", SLOW},
{"smallint", SMALLINT},
{"snapshot", SNAPSHOT},
Expand Down
10 changes: 10 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,18 @@ var (
input: "select /* distinct */ distinct 1 from t",
}, {
input: "select /* straight_join */ straight_join 1 from t",
}, {
input: "select /* for share */ 1 from t for share",
}, {
input: "select /* for share */ 1 from t for share nowait",
}, {
input: "select /* for share */ 1 from t for share skip locked",
}, {
input: "select /* for update */ 1 from t for update",
}, {
input: "select /* for update */ 1 from t for update nowait",
}, {
input: "select /* for update */ 1 from t for update skip locked",
}, {
input: "select /* lock in share mode */ 1 from t lock in share mode",
}, {
Expand Down
Loading

0 comments on commit 38eccb9

Please sign in to comment.