*: parse more lock options in alter table statement (#3260)

* *: parse more  lock options in alter table statement and ignore them
This commit is contained in:
David Chen
2017-05-15 14:29:13 +08:00
committed by GitHub
parent 83a40db1fa
commit 9b8a445aa8
4 changed files with 47 additions and 3 deletions

View File

@ -646,6 +646,18 @@ const (
// TODO: Add more actions
)
// LockType is the type for AlterTableSpec.
// See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html#alter-table-concurrency
type LockType byte
// Lock Types.
const (
LockTypeNone LockType = iota + 1
LockTypeDefault
LockTypeShared
LockTypeExclusive
)
// AlterTableSpec represents alter table specification.
type AlterTableSpec struct {
node
@ -658,6 +670,7 @@ type AlterTableSpec struct {
NewColumn *ColumnDef
OldColumnName *ColumnName
Position *ColumnPosition
LockType LockType
}
// Accept implements Node Accept interface.

View File

@ -248,6 +248,7 @@ var tokenMap = map[string]int{
"ENUM": enum,
"ESCAPE": escape,
"ESCAPED": escaped,
"EXCLUSIVE": exclusive,
"EVENTS": events,
"EXECUTE": execute,
"EXISTS": exists,
@ -413,6 +414,7 @@ var tokenMap = map[string]int{
"SESSION": session,
"SET": set,
"SHARE": share,
"SHARED": shared,
"SHOW": show,
"SLEEP": sleep,
"SIGN": sign,

View File

@ -442,6 +442,7 @@ import (
engine "ENGINE"
engines "ENGINES"
escape "ESCAPE"
exclusive "EXCLUSIVE"
execute "EXECUTE"
fields "FIELDS"
first "FIRST"
@ -483,6 +484,7 @@ import (
serializable "SERIALIZABLE"
session "SESSION"
share "SHARE"
shared "SHARED"
signed "SIGNED"
snapshot "SNAPSHOT"
space "SPACE"
@ -657,6 +659,7 @@ import (
LoadDataStmt "Load data statement"
LocalOpt "Local opt"
LockTablesStmt "Lock tables statement"
LockClause "Alter table lock clause"
LowPriorityOptional "LOW_PRIORITY or empty"
NumLiteral "Num/Int/Float/Decimal Literal"
NoWriteToBinLogAliasOpt "NO_WRITE_TO_BINLOG alias LOCAL or empty"
@ -1030,13 +1033,31 @@ AlterTableSpec:
NewTable: $3.(*ast.TableName),
}
}
| "LOCK" eq "NONE"
| LockClause
{
$$ = &ast.AlterTableSpec{
Tp: ast.AlterTableLock,
LockType: $1.(ast.LockType),
}
}
LockClause:
"LOCK" eq "NONE"
{
$$ = ast.LockTypeNone
}
| "LOCK" eq "DEFAULT"
{
$$ = ast.LockTypeDefault
}
| "LOCK" eq "SHARED"
{
$$ = ast.LockTypeShared
}
| "LOCK" eq "EXCLUSIVE"
{
$$ = ast.LockTypeExclusive
}
KeyOrIndex: "KEY" | "INDEX"
@ -2326,7 +2347,7 @@ UnReservedKeyword:
| "MIN_ROWS" | "NATIONAL" | "ROW" | "ROW_FORMAT" | "QUARTER" | "GRANTS" | "TRIGGERS" | "DELAY_KEY_WRITE" | "ISOLATION" | "JSON"
| "REPEATABLE" | "COMMITTED" | "UNCOMMITTED" | "ONLY" | "SERIALIZABLE" | "LEVEL" | "VARIABLES" | "SQL_CACHE" | "INDEXES" | "PROCESSLIST"
| "SQL_NO_CACHE" | "DISABLE" | "ENABLE" | "REVERSE" | "SPACE" | "PRIVILEGES" | "NO" | "BINLOG" | "FUNCTION" | "VIEW" | "MODIFY" | "EVENTS" | "PARTITIONS"
| "TIMESTAMPDIFF" | "NONE" | "SUPER"
| "TIMESTAMPDIFF" | "NONE" | "SUPER" | "SHARED" | "EXCLUSIVE"
ReservedKeyword:
"ADD" | "ALL" | "ALTER" | "ANALYZE" | "AND" | "AS" | "ASC" | "BETWEEN" | "BIGINT"
@ -3688,6 +3709,7 @@ GetFormatSelector:
$$ = strings.ToUpper($1)
}
FunctionNameDateArith:
"DATE_ADD"
| "DATE_SUB"

View File

@ -91,7 +91,7 @@ func (s *testParserSuite) TestSimple(c *C) {
"compact", "redundant", "sql_no_cache sql_no_cache", "sql_cache sql_cache", "action", "round",
"enable", "disable", "reverse", "space", "privileges", "get_lock", "release_lock", "sleep", "no", "greatest", "least",
"binlog", "hex", "unhex", "function", "indexes", "from_unixtime", "processlist", "events", "less", "than", "timediff",
"ln", "log", "log2", "log10", "timestampdiff", "pi", "quote", "none", "super",
"ln", "log", "log2", "log10", "timestampdiff", "pi", "quote", "none", "super", "default", "shared", "exclusive",
}
for _, kw := range unreservedKws {
src := fmt.Sprintf("SELECT %s FROM tbl;", kw)
@ -1259,6 +1259,13 @@ func (s *testParserSuite) TestDDL(c *C) {
{"ALTER TABLE t ALTER COLUMN a DROP DEFAULT", true},
{"ALTER TABLE t ALTER a DROP DEFAULT", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, lock=none", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, lock=default", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, lock=shared", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, lock=exclusive", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, LOCK=NONE", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, LOCK=DEFAULT", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, LOCK=SHARED", true},
{"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, LOCK=EXCLUSIVE", true},
// for rename table statement
{"RENAME TABLE t TO t1", true},