Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table: fix lazy check key condition in index.Create and AddRecord #51982

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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