Skip to content

Commit

Permalink
ddl: persist index info after changing backfill state (#40229)
Browse files Browse the repository at this point in the history
close #40217
  • Loading branch information
tangenta authored Jan 4, 2023
1 parent ccee532 commit 73c8cc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion executor/batch_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73c8cc7

Please sign in to comment.