diff --git a/executor/executor.go b/executor/executor.go index 84419ee68c915..f104b384aa8b5 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1850,6 +1850,12 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { vars.ClearStmtVars() vars.PrevFoundInBinding = vars.FoundInBinding vars.FoundInBinding = false +<<<<<<< HEAD +======= + vars.DurationWaitTS = 0 + vars.CurrInsertBatchExtraCols = nil + vars.CurrInsertValues = chunk.Row{} +>>>>>>> f600fc694f (executor: reset the related session vars for both INSERT and REPLACE (#40354)) return } diff --git a/executor/insert.go b/executor/insert.go index 8e689a40625b6..e2f6284206dde 100644 --- a/executor/insert.go +++ b/executor/insert.go @@ -315,8 +315,15 @@ func (e *InsertExec) Next(ctx context.Context, req *chunk.Chunk) error { // Close implements the Executor Close interface. func (e *InsertExec) Close() error { +<<<<<<< HEAD e.ctx.GetSessionVars().CurrInsertValues = chunk.Row{} e.ctx.GetSessionVars().CurrInsertBatchExtraCols = e.ctx.GetSessionVars().CurrInsertBatchExtraCols[0:0:0] +======= + if e.runtimeStats != nil && e.stats != nil { + defer e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(e.id, e.stats) + } + defer e.memTracker.ReplaceBytesUsed(0) +>>>>>>> f600fc694f (executor: reset the related session vars for both INSERT and REPLACE (#40354)) e.setMessage() if e.SelectExec != nil { return e.SelectExec.Close() diff --git a/executor/write_test.go b/executor/write_test.go index 3e09172d5d451..ff5b652231f89 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -4029,6 +4029,7 @@ func (s *testSerialSuite) TestIssueInsertPrefixIndexForNonUTF8Collation(c *C) { tk.MustGetErrCode("insert into t3 select 'abc d'", 1062) } +<<<<<<< HEAD:executor/write_test.go func (s *testSerialSuite) TestIssue22496(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -4096,4 +4097,24 @@ func testEqualDatumsAsBinary(c *C, a []interface{}, b []interface{}, same bool) res, err := re.EqualDatumsAsBinary(sc, types.MakeDatums(a...), types.MakeDatums(b...)) c.Assert(err, IsNil) c.Assert(res, Equals, same, Commentf("a: %v, b: %v", a, b)) +======= +func TestMutipleReplaceAndInsertInOneSession(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t_securities(id bigint not null auto_increment primary key, security_id varchar(8), market_id smallint, security_type int, unique key uu(security_id, market_id))") + tk.MustExec(`insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) + tk.MustExec(`replace into t_securities (security_id, market_id, security_type) select security_id+1, 1, security_type from t_securities where security_id="7";`) + tk.MustExec(`INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) + + tk.MustQuery("select * from t_securities").Sort().Check(testkit.Rows("1 1 2 7", "2 7 1 7", "3 8 1 7")) + + tk2 := testkit.NewTestKit(t, store) + tk2.MustExec("use test") + tk2.MustExec(`insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) + tk2.MustExec(`insert into t_securities (security_id, market_id, security_type) select security_id+2, 1, security_type from t_securities where security_id="7";`) + tk2.MustExec(`INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) + + tk2.MustQuery("select * from t_securities").Sort().Check(testkit.Rows("1 1 2 7", "2 7 1 7", "3 8 1 7", "8 9 1 7")) +>>>>>>> f600fc694f (executor: reset the related session vars for both INSERT and REPLACE (#40354)):executor/writetest/write_test.go }