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

executor: fix data inconsistency after load data ... replace into ... (#56415) #56505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,7 @@ func (e *InsertValues) handleDuplicateKey(ctx context.Context, txn kv.Transactio
if handle == nil {
return false, nil
}
_, err = e.removeRow(ctx, txn, handle, r, true)
if err != nil {
return false, err
}
return false, nil
return e.removeRow(ctx, txn, handle, r, true)
}

// batchCheckAndInsert checks rows with duplicate errors.
Expand Down
34 changes: 34 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4291,3 +4291,37 @@ func TestHandleColumnWithOnUpdateCurrentTimestamp(t *testing.T) {
tk.MustExec("update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'")
tk.MustExec("admin check table t")
}

func TestFix56408(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fzzf678 PTAL. I added the test.

It adds two testCase to cover the case that a duplicated rows is loaded in a new query.

store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("USE test; DROP TABLE IF EXISTS load_data_replace;")
tk.MustExec("create table a(id int,name varchar(20),addr varchar(100),primary key (id) nonclustered);")
tk.MustExec("LOAD DATA LOCAL INFILE '/tmp/nonexistence.csv' REPLACE INTO TABLE a FIELDS terminated by '|';")
ctx := tk.Session().(sessionctx.Context)
ld, ok := ctx.Value(executor.LoadDataVarKey).(*executor.LoadDataInfo)
require.True(t, ok)
defer ctx.SetValue(executor.LoadDataVarKey, nil)
require.NotNil(t, ld)

tests := []testCase{
{
nil,
[]byte("1|aa|beijing\n1|aa|beijing\n1|aa|beijing\n1|aa|beijing\n2|bb|shanghai\n2|bb|shanghai\n2|bb|shanghai\n3|cc|guangzhou\n"),
[]string{"1 aa beijing", "2 bb shanghai", "3 cc guangzhou"},
nil,
"Records: 8 Deleted: 0 Skipped: 5 Warnings: 0",
},
{
nil,
[]byte("1|aa|beijing\n1|aa|beijing\n1|aa|beijing\n1|aa|beijing\n2|bb|shanghai\n2|bb|shanghai\n2|bb|shanghai\n3|cc|guangzhou\n"),
[]string{"1 aa beijing", "2 bb shanghai", "3 cc guangzhou"},
nil,
"Records: 8 Deleted: 0 Skipped: 8 Warnings: 0",
},
}
deleteSQL := "DO 1"
selectSQL := "TABLE a;"
checkCases(tests, ld, t, tk, ctx, selectSQL, deleteSQL)
tk.MustExec("ADMIN CHECK TABLE a")
}
Loading