ddl: preserve index order for multi-schema change (#47483)

ref pingcap/tidb#41602
This commit is contained in:
tangenta
2023-10-09 19:43:53 +08:00
committed by GitHub
parent c474445ef7
commit 1f5179a110
2 changed files with 16 additions and 1 deletions

View File

@ -333,7 +333,7 @@ func mergeAddIndex(info *model.MultiSchemaInfo) {
// Foreign key requires the order of adding indexes is unchanged.
return
}
if subJob.Type == model.ActionAddIndex {
if subJob.Type == model.ActionAddIndex || subJob.Type == model.ActionAddPrimaryKey {
if i == 0 {
consistentUnique = subJob.Args[0].(bool)
} else {

View File

@ -1223,6 +1223,21 @@ func TestMultiSchemaChangeAddIndexChangeColumn(t *testing.T) {
tk.MustExec("admin check table t;")
}
func TestMultiSchemaChangeAddIndexOrder(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t (a int);")
tk.MustExec("insert into t values (123);")
tk.MustExec("alter table t add index i(a), add primary key (a);")
result := "t CREATE TABLE `t` (\n" +
" `a` int(11) NOT NULL,\n" +
" KEY `i` (`a`),\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
tk.MustQuery("show create table t;").Check(testkit.Rows(result))
}
func TestMultiSchemaChangeMixedWithUpdate(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)