Merge pull request #66 from github/patrickcarnahan/mysql8-lock-syntax

Add support for new lock syntax in MySQL8
This commit is contained in:
Arthur Schreiber 2023-08-11 13:17:00 +02:00 коммит произвёл GitHub
Родитель 9f9b77f5f2 bc0647767a
Коммит 6b8851d007
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 4415 добавлений и 4185 удалений

Просмотреть файл

@ -1169,6 +1169,16 @@ func (lock Lock) ToString() string {
return NoLockStr return NoLockStr
case ForUpdateLock: case ForUpdateLock:
return ForUpdateStr return ForUpdateStr
case ForUpdateLockNoWait:
return ForUpdateNoWaitStr
case ForUpdateLockSkipLocked:
return ForUpdateSkipLockedStr
case ForShareLock:
return ForShareStr
case ForShareLockNoWait:
return ForShareNoWaitStr
case ForShareLockSkipLocked:
return ForShareSkipLockedStr
case ShareModeLock: case ShareModeLock:
return ShareModeStr return ShareModeStr
default: default:

Просмотреть файл

@ -25,9 +25,14 @@ const (
SQLCalcFoundRowsStr = "sql_calc_found_rows " SQLCalcFoundRowsStr = "sql_calc_found_rows "
// Select.Lock // Select.Lock
NoLockStr = "" NoLockStr = ""
ForUpdateStr = " for update" ForUpdateStr = " for update"
ShareModeStr = " lock in share mode" 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 // Select.Cache
SQLCacheStr = "sql_cache " SQLCacheStr = "sql_cache "
@ -468,6 +473,11 @@ const (
NoLock Lock = iota NoLock Lock = iota
ForUpdateLock ForUpdateLock
ShareModeLock ShareModeLock
ForShareLock
ForShareLockNoWait
ForShareLockSkipLocked
ForUpdateLockNoWait
ForUpdateLockSkipLocked
) )
// Constants for Enum Type - TrimType // Constants for Enum Type - TrimType

Просмотреть файл

@ -403,6 +403,7 @@ var keywords = []keyword{
{"localtimestamp", LOCALTIMESTAMP}, {"localtimestamp", LOCALTIMESTAMP},
{"locate", LOCATE}, {"locate", LOCATE},
{"lock", LOCK}, {"lock", LOCK},
{"locked", LOCKED},
{"logs", LOGS}, {"logs", LOGS},
{"long", UNUSED}, {"long", UNUSED},
{"longblob", LONGBLOB}, {"longblob", LONGBLOB},
@ -447,6 +448,7 @@ var keywords = []keyword{
{"none", NONE}, {"none", NONE},
{"not", NOT}, {"not", NOT},
{"now", NOW}, {"now", NOW},
{"nowait", NOWAIT},
{"no_write_to_binlog", NO_WRITE_TO_BINLOG}, {"no_write_to_binlog", NO_WRITE_TO_BINLOG},
{"nth_value", NTH_VALUE}, {"nth_value", NTH_VALUE},
{"ntile", NTILE}, {"ntile", NTILE},
@ -560,6 +562,7 @@ var keywords = []keyword{
{"signal", UNUSED}, {"signal", UNUSED},
{"signed", SIGNED}, {"signed", SIGNED},
{"simple", SIMPLE}, {"simple", SIMPLE},
{"skip", SKIP},
{"slow", SLOW}, {"slow", SLOW},
{"smallint", SMALLINT}, {"smallint", SMALLINT},
{"spatial", SPATIAL}, {"spatial", SPATIAL},

Просмотреть файл

@ -371,8 +371,18 @@ var (
input: "select /* distinct */ distinct 1 from t", input: "select /* distinct */ distinct 1 from t",
}, { }, {
input: "select /* straight_join */ straight_join 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",
}, {
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", input: "select /* lock in share mode */ 1 from t lock in share mode",
}, { }, {

8539
go/vt/sqlparser/sql.go сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -6868,6 +6868,26 @@ FOR UPDATE
{ {
$$ = ForUpdateLock $$ = ForUpdateLock
} }
| FOR UPDATE NOWAIT
{
$$ = ForUpdateLockNoWait
}
| FOR UPDATE SKIP LOCKED
{
$$ = ForUpdateLockSkipLocked
}
| FOR SHARE
{
$$ = ForShareLock
}
| FOR SHARE NOWAIT
{
$$ = ForShareLockNoWait
}
| FOR SHARE SKIP LOCKED
{
$$ = ForShareLockSkipLocked
}
| LOCK IN SHARE MODE | LOCK IN SHARE MODE
{ {
$$ = ShareModeLock $$ = ShareModeLock

2
go/vt/sqlparser/testdata/union_cases.txt поставляемый
Просмотреть файл

@ -1004,7 +1004,7 @@ INPUT
SELECT 1 FOR SHARE UNION SELECT 2; SELECT 1 FOR SHARE UNION SELECT 2;
END END
ERROR ERROR
syntax error at position 19 near 'SHARE' syntax error at position 25 near 'UNION'
END END
INPUT INPUT
SELECT ST_AsText(ST_Union(shore, boundary)) FROM lakes, named_places WHERE lakes.name = 'Blue Lake' AND named_places.name = 'Goose Island'; SELECT ST_AsText(ST_Union(shore, boundary)) FROM lakes, named_places WHERE lakes.name = 'Blue Lake' AND named_places.name = 'Goose Island';