Skip to content

Commit

Permalink
Support ALTER TABLE REBUILD PARTITION syntax (pingcap#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
spongedu authored and leoppro committed Aug 16, 2019
1 parent ad0c07f commit ac4b12a
Show file tree
Hide file tree
Showing 4 changed files with 7,045 additions and 6,986 deletions.
18 changes: 17 additions & 1 deletion ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ const (
AlterTableRemovePartitioning
AlterTableWithValidation
AlterTableWithoutValidation
AlterTableRebuildPartition
AlterTableCheckPartitions
AlterTableExchangePartition
AlterTableOptimizePartition
Expand Down Expand Up @@ -1895,8 +1896,8 @@ type AlterTableSpec struct {
// see https://mariadb.com/kb/en/library/alter-table/
IfNotExists bool

OnAllPartitions bool
NoWriteToBinlog bool
OnAllPartitions bool

Tp AlterTableType
Name string
Expand Down Expand Up @@ -2205,6 +2206,21 @@ func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("WITH VALIDATION")
case AlterTableWithoutValidation:
ctx.WriteKeyWord("WITHOUT VALIDATION")
case AlterTableRebuildPartition:
ctx.WriteKeyWord("REBUILD PARTITION ")
if n.NoWriteToBinlog {
ctx.WriteKeyWord("NO_WRITE_TO_BINLOG ")
}
if n.OnAllPartitions {
ctx.WriteKeyWord("ALL")
return nil
}
for i, name := range n.PartitionNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(name.O)
}
case AlterTableExchangePartition:
ctx.WriteKeyWord("EXCHANGE PARTITION ")
ctx.WriteName(n.PartitionNames[0].O)
Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ var tokenMap = map[string]int{
"PRE_SPLIT_REGIONS": preSplitRegions,
"RANGE": rangeKwd,
"RECOVER": recover,
"REBUILD": rebuild,
"READ": read,
"READ_CONSISTENT_REPLICA": hintReadConsistentReplica,
"REAL": realType,
Expand Down
Loading

0 comments on commit ac4b12a

Please sign in to comment.