Skip to content

Commit

Permalink
parser: add 'INSTANT' alter algorithm (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
winkyao committed Feb 19, 2019
1 parent 64957c5 commit 362712b
Show file tree
Hide file tree
Showing 5 changed files with 5,722 additions and 5,649 deletions.
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

0 comments on commit 362712b

Please sign in to comment.