ddl: fix a bug that dropping primary key lead to implicit invisible primary key success (#19281)
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
This commit is contained in:
15
ddl/index.go
15
ddl/index.go
@ -687,6 +687,21 @@ func checkDropIndex(t *meta.Meta, job *model.Job) (*model.TableInfo, *model.Inde
|
||||
return nil, nil, autoid.ErrWrongAutoKey
|
||||
}
|
||||
|
||||
// Check that drop primary index will not cause invisible implicit primary index.
|
||||
newIndices := make([]*model.IndexInfo, 0, len(tblInfo.Indices))
|
||||
for _, idx := range tblInfo.Indices {
|
||||
if idx.Name.L != indexInfo.Name.L {
|
||||
newIndices = append(newIndices, idx)
|
||||
}
|
||||
}
|
||||
newTbl := tblInfo.Clone()
|
||||
newTbl.Indices = newIndices
|
||||
err = checkInvisibleIndexOnPK(newTbl)
|
||||
if err != nil {
|
||||
job.State = model.JobStateCancelled
|
||||
return nil, nil, errors.Trace(err)
|
||||
}
|
||||
|
||||
return tblInfo, indexInfo, nil
|
||||
}
|
||||
|
||||
|
||||
@ -1379,6 +1379,8 @@ func (s *testSerialSuite) TestInvisibleIndex(c *C) {
|
||||
tk.MustExec("insert into t6 values (1, 2)")
|
||||
tk.MustQuery("select * from t6").Check(testkit.Rows("1 2"))
|
||||
tk.MustGetErrCode("alter table t6 drop primary key", errno.ErrPKIndexCantBeInvisible)
|
||||
res := tk.MustQuery("show index from t6 where Key_name='PRIMARY';")
|
||||
c.Check(len(res.Rows()), Equals, 1)
|
||||
}
|
||||
|
||||
func (s *testSerialSuite) TestCreateClusteredIndex(c *C) {
|
||||
|
||||
Reference in New Issue
Block a user