diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index bb045d6ff80b0..acf26a2cb0e68 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2649,16 +2649,17 @@ func (s *testIntegrationSuite3) TestAutoIncrementForce(c *C) { } // Rebase _tidb_row_id. tk.MustExec("create table t (a int);") + tk.MustExec("alter table t force auto_increment = 2;") tk.MustExec("insert into t values (1),(2);") - tk.MustQuery("select a, _tidb_rowid from t;").Check(testkit.Rows("1 1", "2 2")) + tk.MustQuery("select a, _tidb_rowid from t;").Check(testkit.Rows("1 2", "2 3")) // Cannot set next global ID to 0. tk.MustGetErrCode("alter table t force auto_increment = 0;", errno.ErrAutoincReadFailed) tk.MustExec("alter table t force auto_increment = 1;") c.Assert(getNextGlobalID(), Equals, uint64(1)) // inserting new rows can overwrite the existing data. tk.MustExec("insert into t values (3);") - tk.MustExec("insert into t values (3);") - tk.MustQuery("select a, _tidb_rowid from t;").Check(testkit.Rows("3 1", "3 2")) + c.Assert(tk.ExecToErr("insert into t values (3);").Error(), Equals, "[kv:1062]Duplicate entry '2' for key 'PRIMARY'") + tk.MustQuery("select a, _tidb_rowid from t;").Check(testkit.Rows("3 1", "1 2", "2 3")) // Rebase auto_increment. tk.MustExec("drop table if exists t;") diff --git a/table/index.go b/table/index.go index 0b64adb484446..7974974d879fa 100644 --- a/table/index.go +++ b/table/index.go @@ -32,9 +32,8 @@ type IndexIterator interface { // CreateIdxOpt contains the options will be used when creating an index. type CreateIdxOpt struct { - Ctx context.Context - SkipHandleCheck bool // If true, skip the handle constraint check. - Untouched bool // If true, the index key/value is no need to commit. + Ctx context.Context + Untouched bool // If true, the index key/value is no need to commit. } // CreateIdxOptFunc is defined for the Create() method of Index interface. @@ -42,11 +41,6 @@ type CreateIdxOpt struct { // https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis type CreateIdxOptFunc func(*CreateIdxOpt) -// SkipHandleCheck is a defined value of CreateIdxFunc. -var SkipHandleCheck CreateIdxOptFunc = func(opt *CreateIdxOpt) { - opt.SkipHandleCheck = true -} - // IndexIsUntouched uses to indicate the index kv is untouched. var IndexIsUntouched CreateIdxOptFunc = func(opt *CreateIdxOpt) { opt.Untouched = true diff --git a/table/tables/tables.go b/table/tables/tables.go index 20504dd21a4f1..3ef849ca91391 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -787,8 +787,7 @@ func (t *TableCommon) AddRecord(sctx sessionctx.Context, r []types.Datum, opts . value := writeBufs.RowValBuf var setPresume bool - skipCheck := sctx.GetSessionVars().StmtCtx.BatchCheck - if (t.meta.IsCommonHandle || t.meta.PKIsHandle) && !skipCheck && !opt.SkipHandleCheck { + if !sctx.GetSessionVars().StmtCtx.BatchCheck { if t.meta.TempTableType != model.TempTableNone { // Always check key for temporary table because it does not write to TiKV _, err = txn.Get(ctx, key)