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

Add support for new lock syntax in MySQL8 #13965

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading