Skip to content

Commit ba10a69

Browse files
authored
executor: fix data inconsistency after load data ... replace into ... (#56415) (#56984)
close #56408
1 parent 2687bd8 commit ba10a69

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

pkg/executor/insert_common.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,7 @@ func (e *InsertValues) handleDuplicateKey(ctx context.Context, txn kv.Transactio
11801180
if handle == nil {
11811181
return false, nil
11821182
}
1183-
_, err = e.removeRow(ctx, txn, handle, r, true)
1184-
if err != nil {
1185-
return false, err
1186-
}
1187-
return false, nil
1183+
return e.removeRow(ctx, txn, handle, r, true)
11881184
}
11891185

11901186
// batchCheckAndInsert checks rows with duplicate errors.

pkg/executor/test/loaddatatest/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_test(
99
],
1010
flaky = True,
1111
race = "on",
12-
shard_count = 11,
12+
shard_count = 12,
1313
deps = [
1414
"//pkg/config",
1515
"//pkg/executor",

pkg/executor/test/loaddatatest/load_data_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,22 @@ func TestLoadDataFromServerFile(t *testing.T) {
472472
err := tk.ExecToErr("load data infile 'remote.csv' into table load_data_test")
473473
require.ErrorContains(t, err, "[executor:8154]Don't support load data from tidb-server's disk.")
474474
}
475+
476+
func TestFix56408(t *testing.T) {
477+
store := testkit.CreateMockStore(t)
478+
tk := testkit.NewTestKit(t, store)
479+
tk.MustExec("USE test; DROP TABLE IF EXISTS load_data_replace;")
480+
tk.MustExec("create table a(id int,name varchar(20),addr varchar(100),primary key (id) nonclustered);")
481+
loadSQL := "LOAD DATA LOCAL INFILE '/tmp/nonexistence.csv' REPLACE INTO TABLE a FIELDS terminated by '|';"
482+
ctx := tk.Session().(sessionctx.Context)
483+
tests := []testCase{
484+
{[]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"),
485+
[]string{"1 aa beijing", "2 bb shanghai", "3 cc guangzhou"},
486+
"Records: 8 Deleted: 0 Skipped: 5 Warnings: 0",
487+
},
488+
}
489+
deleteSQL := "DO 1"
490+
selectSQL := "TABLE a;"
491+
checkCases(tests, loadSQL, t, tk, ctx, selectSQL, deleteSQL)
492+
tk.MustExec("ADMIN CHECK TABLE a")
493+
}

0 commit comments

Comments
 (0)