From c3107e81877012b5a128032068819159fff21fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A7=E5=86=B0?= Date: Wed, 1 Sep 2021 23:25:37 +0800 Subject: [PATCH] update func: isSameTypeMultiSpecs --- ddl/ddl_api.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 519e32cada2d4..1d028cbb83207 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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 } } @@ -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 }