Skip to content

Commit

Permalink
update func: isSameTypeMultiSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
ou-bing committed Sep 1, 2021
1 parent 681cd4a commit c3107e8
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,16 +2410,11 @@ func resolveAlterTableSpec(ctx sessionctx.Context, specs []*ast.AlterTableSpec)
func isSameTypeMultiSpecs(specs []*ast.AlterTableSpec) bool {
specType := specs[0].Tp
for _, spec := range specs {
if spec.Tp != specType {
return false
// We think AlterTableDropPrimaryKey and AlterTableDropIndex are the same types.
if spec.Tp == ast.AlterTableDropPrimaryKey || spec.Tp == ast.AlterTableDropIndex {
continue
}
}
return true
}

func isDropIndexes(specs []*ast.AlterTableSpec) bool {
for _, spec := range specs {
if spec.Tp != ast.AlterTableDropPrimaryKey && spec.Tp != ast.AlterTableDropIndex {
if spec.Tp != specType {
return false
}
}
Expand All @@ -2442,19 +2437,14 @@ func (d *ddl) AlterTable(ctx context.Context, sctx sessionctx.Context, ident ast
return errRunMultiSchemaChanges
}

if isDropIndexes(validSpecs) {
if err = d.DropIndexes(sctx, ident, validSpecs); err != nil {
return errors.Trace(err)
}
return nil
}

if isSameTypeMultiSpecs(validSpecs) {
switch validSpecs[0].Tp {
case ast.AlterTableAddColumns:
err = d.AddColumns(sctx, ident, validSpecs)
case ast.AlterTableDropColumn:
err = d.DropColumns(sctx, ident, validSpecs)
case ast.AlterTableDropPrimaryKey, ast.AlterTableDropIndex:
err = d.DropIndexes(sctx, ident, validSpecs)
default:
return errRunMultiSchemaChanges
}
Expand Down

0 comments on commit c3107e8

Please sign in to comment.