diff --git a/ddl/index.go b/ddl/index.go index 306723964a693..9690f13a2e6a0 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -871,7 +871,8 @@ func doReorgWorkForCreateIndex(w *worker, d *ddlCtx, t *meta.Meta, job *model.Jo return false, ver, err } indexInfo.BackfillState = model.BackfillStateInapplicable // Prevent double-write on this index. - return true, ver, nil + ver, err = updateVersionAndTableInfo(d, t, job, tbl.Meta(), true) + return true, ver, err default: return false, 0, dbterror.ErrInvalidDDLState.GenWithStackByArgs("backfill", indexInfo.BackfillState) } diff --git a/ddl/multi_schema_change_test.go b/ddl/multi_schema_change_test.go index 9f84ca6aeeed8..a8d6f01e63ac6 100644 --- a/ddl/multi_schema_change_test.go +++ b/ddl/multi_schema_change_test.go @@ -1208,6 +1208,17 @@ func TestMultiSchemaChangeSchemaVersion(t *testing.T) { dom.DDL().SetHook(originHook) } +func TestMultiSchemaChangeAddIndexChangeColumn(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test;") + tk.MustExec("CREATE TABLE t (a SMALLINT DEFAULT '30219', b TIME NULL DEFAULT '02:45:06', PRIMARY KEY (a));") + tk.MustExec("ALTER TABLE t ADD unique INDEX idx4 (b), change column a e MEDIUMINT DEFAULT '5280454' FIRST;") + tk.MustExec("insert ignore into t (e) values (5586359),(501788),(-5961048),(220083),(-4917129),(-7267211),(7750448);") + tk.MustQuery("select * from t;").Check(testkit.Rows("5586359 02:45:06")) + tk.MustExec("admin check table t;") +} + func TestMultiSchemaChangeMixedWithUpdate(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/executor/batch_checker.go b/executor/batch_checker.go index 79a6748b2d5c3..70466cbd22cd0 100644 --- a/executor/batch_checker.go +++ b/executor/batch_checker.go @@ -181,7 +181,7 @@ func getKeysNeedCheckOneRow(ctx sessionctx.Context, t table.Table, row []types.D continue } // If index is used ingest ways, then we should check key from temp index. - if v.Meta().BackfillState != model.BackfillStateInapplicable { + if v.Meta().State != model.StatePublic && v.Meta().BackfillState != model.BackfillStateInapplicable { _, key, _ = tables.GenTempIdxKeyByState(v.Meta(), key) } colValStr, err1 := formatDataForDupError(colVals)