Skip to content

Commit

Permalink
executor: fix data inconsistency after `load data ... replace into ..…
Browse files Browse the repository at this point in the history
….` (#56415)

close #56408
  • Loading branch information
fzzf678 authored Oct 8, 2024
1 parent 9d2227d commit 7daf026
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 1 addition & 5 deletions pkg/executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,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
2 changes: 1 addition & 1 deletion pkg/executor/test/loaddatatest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 11,
shard_count = 12,
deps = [
"//pkg/config",
"//pkg/executor",
Expand Down
19 changes: 19 additions & 0 deletions pkg/executor/test/loaddatatest/load_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,22 @@ func TestLoadDataFromServerFile(t *testing.T) {
err := tk.ExecToErr("load data infile 'remote.csv' into table load_data_test")
require.ErrorContains(t, err, "[executor:8154]Don't support load data from tidb-server's disk.")
}

func TestFix56408(t *testing.T) {
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);")
loadSQL := "LOAD DATA LOCAL INFILE '/tmp/nonexistence.csv' REPLACE INTO TABLE a FIELDS terminated by '|';"
ctx := tk.Session().(sessionctx.Context)
tests := []testCase{
{[]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"},
"Records: 8 Deleted: 0 Skipped: 5 Warnings: 0",
},
}
deleteSQL := "DO 1"
selectSQL := "TABLE a;"
checkCases(tests, loadSQL, t, tk, ctx, selectSQL, deleteSQL)
tk.MustExec("ADMIN CHECK TABLE a")
}

0 comments on commit 7daf026

Please sign in to comment.