Skip to content

Commit d19fd31

Browse files
tiancaiamaowinkyao
authored andcommitted
executor: fix a bug of 'insert on duplicate update' statement… (#11231)
1 parent f83a13b commit d19fd31

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

executor/insert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (e *InsertExec) Open(ctx context.Context) error {
169169

170170
// updateDupRow updates a duplicate row to a new row.
171171
func (e *InsertExec) updateDupRow(row toBeCheckedRow, handle int64, onDuplicate []*expression.Assignment) error {
172-
oldRow, err := e.getOldRow(e.ctx, e.Table, handle, e.GenExprs)
172+
oldRow, err := e.getOldRow(e.ctx, row.t, handle, e.GenExprs)
173173
if err != nil {
174174
logutil.Logger(context.Background()).Error("get old row failed when insert on dup", zap.Int64("handle", handle), zap.String("toBeInsertedRow", types.DatumsToStrNoErr(row.row)))
175175
return err

executor/insert_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,17 @@ func (s *testSuite3) TestAllowInvalidDates(c *C) {
286286
runWithMode("STRICT_TRANS_TABLES,ALLOW_INVALID_DATES")
287287
runWithMode("ALLOW_INVALID_DATES")
288288
}
289+
290+
func (s *testSuite3) TestPartitionInsertOnDuplicate(c *C) {
291+
tk := testkit.NewTestKit(c, s.store)
292+
tk.MustExec(`use test`)
293+
tk.MustExec(`create table t1 (a int,b int,primary key(a,b)) partition by range(a) (partition p0 values less than (100),partition p1 values less than (1000))`)
294+
tk.MustExec(`insert into t1 set a=1, b=1`)
295+
tk.MustExec(`insert into t1 set a=1,b=1 on duplicate key update a=1,b=1`)
296+
tk.MustQuery(`select * from t1`).Check(testkit.Rows("1 1"))
297+
298+
tk.MustExec(`create table t2 (a int,b int,primary key(a,b)) partition by hash(a) partitions 4`)
299+
tk.MustExec(`insert into t2 set a=1,b=1;`)
300+
tk.MustExec(`insert into t2 set a=1,b=1 on duplicate key update a=1,b=1`)
301+
tk.MustQuery(`select * from t2`).Check(testkit.Rows("1 1"))
302+
}

executor/simple_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,19 @@ func (s *testFlushSuite) TestFlushPrivilegesPanic(c *C) {
405405
c.Assert(err, IsNil)
406406
defer store.Close()
407407

408-
config.GetGlobalConfig().Security.SkipGrantTable = true
408+
saveConf := config.GetGlobalConfig()
409+
conf := config.NewConfig()
410+
conf.Security.SkipGrantTable = true
411+
config.StoreGlobalConfig(conf)
412+
409413
dom, err := session.BootstrapSession(store)
410414
c.Assert(err, IsNil)
411415
defer dom.Close()
412416

413417
tk := testkit.NewTestKit(c, store)
414418
tk.MustExec("FLUSH PRIVILEGES")
415-
config.GetGlobalConfig().Security.SkipGrantTable = false
419+
420+
config.StoreGlobalConfig(saveConf)
416421
}
417422

418423
func (s *testSuite3) TestDropStats(c *C) {

0 commit comments

Comments
 (0)