Skip to content

Commit

Permalink
fix: lazy check key condition in index.Create and AddRecord
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed Mar 21, 2024
1 parent 735adb0 commit 482a01e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/table/tables/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (c *index) Create(sctx table.MutateContext, txn kv.Transaction, indexedValu
// The index key value is not found or deleted.
if err != nil || len(value) == 0 || (!tempIdxVal.IsEmpty() && tempIdxVal.Current().Delete) {
val := idxVal
lazyCheck := (txn.IsPipelined() || sctx.GetSessionVars().LazyCheckKeyNotExists()) && err != nil
lazyCheck := sctx.GetSessionVars().LazyCheckKeyNotExists() && err != nil
if keyIsTempIdxKey {
tempVal := tablecodec.TempIndexValueElem{Value: idxVal, KeyVer: keyVer, Distinct: true}
val = tempVal.Encode(value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func (t *TableCommon) AddRecord(sctx table.MutateContext, r []types.Datum, opts
if t.meta.TempTableType != model.TempTableNone {
// Always check key for temporary table because it does not write to TiKV
_, err = txn.Get(ctx, key)
} else if sctx.GetSessionVars().LazyCheckKeyNotExists() || txn.IsPipelined() {
} else if sctx.GetSessionVars().LazyCheckKeyNotExists() {
var v []byte
v, err = txn.GetMemBuffer().GetLocal(ctx, key)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions tests/realtikvtest/pipelineddmltest/pipelineddml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ func TestInsertIgnoreOnDuplicateKeyUpdate(t *testing.T) {
tk.MustExec("insert ignore into t1 values (0, 2) ,(1, 3) on duplicate key update b = 5, a = 0")
// if the statement execute successful, the following check should pass.
tk.MustQuery("select * from t1").Sort().Check(testkit.Rows("0 5", "1 1"))

tk.MustExec(`create table tbl_2 (col_3 varchar (207),col_4 boolean, primary key (col_4));`)
tk.MustExec(`insert into tbl_2 values ( 'bbb', 0 );`)
tk.MustExec(`insert into tbl_2 values ( 'ccc', 1 );`)
tk.MustExec(
`insert ignore into tbl_2 set col_3 = 'ddd',
col_4 = 0 on duplicate key update col_4 = 1, col_3 = 'eee';`,
)
}

func TestConflictError(t *testing.T) {
Expand Down

0 comments on commit 482a01e

Please sign in to comment.