Skip to content

Commit

Permalink
Add support for new lock syntax in MySQL8 (vitessio#13965)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Carnahan <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
Co-authored-by: Patrick Carnahan <[email protected]>
Co-authored-by: Harshit Gangal <[email protected]>
  • Loading branch information
3 people authored and ejortegau committed Dec 13, 2023
1 parent b6ce0a0 commit cf5f274
Show file tree
Hide file tree
Showing 8 changed files with 6,064 additions and 5,861 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 @@ -1325,6 +1325,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 @@ -27,9 +27,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 @@ -516,6 +521,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 @@ -413,6 +413,7 @@ var keywords = []keyword{
{"localtimestamp", LOCALTIMESTAMP},
{"locate", LOCATE},
{"lock", LOCK},
{"locked", LOCKED},
{"logs", LOGS},
{"long", UNUSED},
{"longblob", LONGBLOB},
Expand Down Expand Up @@ -457,6 +458,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 @@ -575,6 +577,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 @@ -693,8 +693,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 cf5f274

Please sign in to comment.