Skip to content

Commit

Permalink
tables: fix the wrong result for "insert ignore duplicate up" on part…
Browse files Browse the repository at this point in the history
…ition table when handle changed (#25859)
  • Loading branch information
lysu authored Aug 12, 2021
1 parent 05f97c8 commit 702bed1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@ func (s *testSuite4) TestInsertIgnoreOnDup(c *C) {
tk.MustQuery("select * from t6").Check(testkit.Rows("100 10 20"))
tk.MustExec("insert ignore into t6 set a = 200, b= 10 on duplicate key update c = 1000")
tk.MustQuery("select * from t6").Check(testkit.Rows("100 10 1000"))

tk.MustExec("drop table if exists t7")
tk.MustExec("CREATE TABLE t7 (`col_334` mediumint(9) NOT NULL DEFAULT '-3217641', `col_335` mediumint(8) unsigned NOT NULL DEFAULT '2002468', `col_336` enum('alice','bob','charlie','david') COLLATE utf8_general_ci NOT NULL DEFAULT 'alice', PRIMARY KEY (`col_334`,`col_336`,`col_335`) CLUSTERED, UNIQUE KEY `idx_116` (`col_334`,`col_335`), UNIQUE KEY `idx_117` (`col_336`,`col_334`), KEY `idx_118` (`col_336`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PARTITION BY HASH( `col_334` ) PARTITIONS 6;")
tk.MustExec("insert into t7(col_335, col_336) values(7685969, 'alice'),(2002468, 'bob')")
tk.MustExec("insert ignore into t7(col_335, col_336) values(2002468, 'david') on duplicate key update col_335 = 7685969")
tk.MustQuery("select * from t7").Check(testkit.Rows("-3217641 7685969 alice", "-3217641 2002468 bob"))
}

func (s *testSuite4) TestInsertSetWithDefault(c *C) {
Expand Down
4 changes: 3 additions & 1 deletion table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ func FindIndexByColName(t table.Table, name string) table.Index {
// otherwise return kv.ErrKeyExists error.
func CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore(ctx context.Context, sctx sessionctx.Context, t table.Table, recordID kv.Handle, newRow []types.Datum, modified []bool) error {
physicalTableID := t.Meta().ID
idxs := t.Indices()
if pt, ok := t.(*partitionedTable); ok {
info := t.Meta().GetPartitionInfo()
pid, err := pt.locatePartition(sctx, info, newRow)
Expand All @@ -1459,6 +1460,7 @@ func CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore(ctx context.C
}
partition := pt.GetPartition(pid)
physicalTableID = partition.GetPhysicalID()
idxs = partition.Indices()
}
txn, err := sctx.Txn(true)
if err != nil {
Expand Down Expand Up @@ -1492,7 +1494,7 @@ func CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore(ctx context.C
return true
}

for _, idx := range t.Indices() {
for _, idx := range idxs {
if shouldSkipIgnoreCheck(idx) {
continue
}
Expand Down

0 comments on commit 702bed1

Please sign in to comment.