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

ddl: fix drop index failed when index contain auto_increment column and the auto_increment column is primary key (#15861) #16008

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ func checkDropIndex(t *meta.Meta, job *model.Job) (*model.TableInfo, *model.Inde
func checkDropIndexOnAutoIncrementColumn(tblInfo *model.TableInfo, indexInfo *model.IndexInfo) error {
cols := tblInfo.Columns
for _, idxCol := range indexInfo.Columns {
if !mysql.HasAutoIncrementFlag(cols[idxCol.Offset].Flag) {
flag := cols[idxCol.Offset].Flag
if !mysql.HasAutoIncrementFlag(flag) {
continue
}
// check the count of index on auto_increment column.
Expand All @@ -605,6 +606,9 @@ func checkDropIndexOnAutoIncrementColumn(tblInfo *model.TableInfo, indexInfo *mo
}
}
}
if tblInfo.PKIsHandle && mysql.HasPriKeyFlag(flag) {
count++
}
if count < 2 {
return autoid.ErrWrongAutoKey
}
Expand Down
8 changes: 8 additions & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ func (s *testSerialSuite) TestPrimaryKey(c *C) {
c.Assert(err.Error(), Equals, "[ddl:206]Unsupported drop primary key when alter-primary-key is false")
}

func (s *testSerialSuite) TestDropAutoIncrementIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int(11) not null auto_increment key, b int(11), c bigint, unique key (a, b, c))")
tk.MustExec("alter table t1 drop index a")
}

func (s *testSerialSuite) TestMultiRegionGetTableEndHandle(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("drop database if exists test_get_endhandle")
Expand Down