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 <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
  • Loading branch information
patrickcarnahan authored and arthurschreiber committed Mar 5, 2024
1 parent d3cd5d2 commit 86f289c
Show file tree
Hide file tree
Showing 7 changed files with 3,114 additions and 3,111 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 @@ -1174,6 +1174,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 @@ -527,6 +532,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 @@ -412,6 +412,7 @@ var keywords = []keyword{
{"localtimestamp", LOCALTIMESTAMP},
{"locate", LOCATE},
{"lock", LOCK},
{"locked", LOCKED},
{"logs", LOGS},
{"long", UNUSED},
{"longblob", LONGBLOB},
Expand Down Expand Up @@ -456,6 +457,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 @@ -574,6 +576,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 @@ -685,8 +685,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 86f289c

Please sign in to comment.