Skip to content

Commit bc06477

Browse files
add new lock syntax for mysql8
Signed-off-by: Patrick Carnahan <[email protected]>
1 parent 9f9b77f commit bc06477

File tree

7 files changed

+2936
-2706
lines changed

7 files changed

+2936
-2706
lines changed

go/vt/sqlparser/ast_funcs.go

+10
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,16 @@ func (lock Lock) ToString() string {
11691169
return NoLockStr
11701170
case ForUpdateLock:
11711171
return ForUpdateStr
1172+
case ForUpdateLockNoWait:
1173+
return ForUpdateNoWaitStr
1174+
case ForUpdateLockSkipLocked:
1175+
return ForUpdateSkipLockedStr
1176+
case ForShareLock:
1177+
return ForShareStr
1178+
case ForShareLockNoWait:
1179+
return ForShareNoWaitStr
1180+
case ForShareLockSkipLocked:
1181+
return ForShareSkipLockedStr
11721182
case ShareModeLock:
11731183
return ShareModeStr
11741184
default:

go/vt/sqlparser/constants.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ const (
2525
SQLCalcFoundRowsStr = "sql_calc_found_rows "
2626

2727
// Select.Lock
28-
NoLockStr = ""
29-
ForUpdateStr = " for update"
30-
ShareModeStr = " lock in share mode"
28+
NoLockStr = ""
29+
ForUpdateStr = " for update"
30+
ForUpdateNoWaitStr = " for update nowait"
31+
ForUpdateSkipLockedStr = " for update skip locked"
32+
ForShareStr = " for share"
33+
ForShareNoWaitStr = " for share nowait"
34+
ForShareSkipLockedStr = " for share skip locked"
35+
ShareModeStr = " lock in share mode"
3136

3237
// Select.Cache
3338
SQLCacheStr = "sql_cache "
@@ -468,6 +473,11 @@ const (
468473
NoLock Lock = iota
469474
ForUpdateLock
470475
ShareModeLock
476+
ForShareLock
477+
ForShareLockNoWait
478+
ForShareLockSkipLocked
479+
ForUpdateLockNoWait
480+
ForUpdateLockSkipLocked
471481
)
472482

473483
// Constants for Enum Type - TrimType

go/vt/sqlparser/keywords.go

+3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ var keywords = []keyword{
403403
{"localtimestamp", LOCALTIMESTAMP},
404404
{"locate", LOCATE},
405405
{"lock", LOCK},
406+
{"locked", LOCKED},
406407
{"logs", LOGS},
407408
{"long", UNUSED},
408409
{"longblob", LONGBLOB},
@@ -447,6 +448,7 @@ var keywords = []keyword{
447448
{"none", NONE},
448449
{"not", NOT},
449450
{"now", NOW},
451+
{"nowait", NOWAIT},
450452
{"no_write_to_binlog", NO_WRITE_TO_BINLOG},
451453
{"nth_value", NTH_VALUE},
452454
{"ntile", NTILE},
@@ -560,6 +562,7 @@ var keywords = []keyword{
560562
{"signal", UNUSED},
561563
{"signed", SIGNED},
562564
{"simple", SIMPLE},
565+
{"skip", SKIP},
563566
{"slow", SLOW},
564567
{"smallint", SMALLINT},
565568
{"spatial", SPATIAL},

go/vt/sqlparser/parse_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,18 @@ var (
371371
input: "select /* distinct */ distinct 1 from t",
372372
}, {
373373
input: "select /* straight_join */ straight_join 1 from t",
374+
}, {
375+
input: "select /* for share */ 1 from t for share",
376+
}, {
377+
input: "select /* for share */ 1 from t for share nowait",
378+
}, {
379+
input: "select /* for share */ 1 from t for share skip locked",
374380
}, {
375381
input: "select /* for update */ 1 from t for update",
382+
}, {
383+
input: "select /* for update */ 1 from t for update nowait",
384+
}, {
385+
input: "select /* for update */ 1 from t for update skip locked",
376386
}, {
377387
input: "select /* lock in share mode */ 1 from t lock in share mode",
378388
}, {

0 commit comments

Comments
 (0)