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

parser: add 'INSTANT' alter algorithm #93

Merged
merged 10 commits into from
Feb 19, 2019
34 changes: 31 additions & 3 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,35 @@ const (
LockTypeExclusive
)

// AlterAlgorithm is the algorithm of the DDL operations.
// See https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#alter-table-performance.
type AlterAlgorithm byte

// DDL alter algorithms.
// For now, TiDB only supported inplace and instance algorithms. If the user specify `copy`,
// will get an error.
const (
AlterAlgorithmDefault AlterAlgorithm = iota
AlterAlgorithmCopy
AlterAlgorithmInplace
AlterAlgorithmInstant
)

func (a AlterAlgorithm) String() string {
switch a {
case AlterAlgorithmDefault:
return "DEFAULT"
case AlterAlgorithmCopy:
return "COPY"
case AlterAlgorithmInplace:
return "INPLACE"
case AlterAlgorithmInstant:
return "INSTANT"
default:
return "DEFAULT"
}
}

// AlterTableSpec represents alter table specification.
type AlterTableSpec struct {
node
Expand All @@ -1422,6 +1451,7 @@ type AlterTableSpec struct {
OldColumnName *ColumnName
Position *ColumnPosition
LockType LockType
Algorithm AlterAlgorithm
Comment string
FromKey model.CIStr
ToKey model.CIStr
Expand Down Expand Up @@ -1543,11 +1573,9 @@ func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
ctx.WritePlain("= ")
ctx.WriteKeyWord(n.LockType.String())
case AlterTableAlgorithm:
// TODO: not support
ctx.WriteKeyWord("ALGORITHM ")
ctx.WritePlain("= ")
ctx.WriteKeyWord("DEFAULT")
ctx.WritePlain(" /* AlterTableAlgorithm is not supported */ ")
ctx.WriteKeyWord(n.Algorithm.String())
case AlterTableRenameIndex:
ctx.WriteKeyWord("RENAME INDEX ")
ctx.WriteName(n.FromKey.O)
Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ var tokenMap = map[string]int{
"INFILE": infile,
"INNER": inner,
"INPLACE": inplace,
"INSTANT": instant,
"INSERT": insert,
"INT": intType,
"INT1": int1Type,
Expand Down
Loading