Skip to content

Commit

Permalink
session: reset CTEStorageMap before txn conflict and retry() (#49399) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 22, 2023
1 parent 1cc4f87 commit 380a07a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,23 @@ func TestCTESmallChunkSize(t *testing.T) {
tk.MustQuery("with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 1 offset 100) select * from cte1;").Check(testkit.Rows("100"))
tk.MustExec("set @@tidb_max_chunk_size = default;")
}

func TestIssue46522(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk1 := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk1.MustExec("use test;")

tk.MustExec("create table issue46522 (id int primary key);")
tk.MustExec("insert into issue46522 values (1);")
tk.MustExec("set @@tidb_disable_txn_auto_retry = off;")
tk.MustExec("begin optimistic;")
tk.MustExec("insert into issue46522 with t1 as (select id+1 from issue46522 where id = 1) select * from t1;")

tk1.MustExec("begin optimistic;")
tk1.MustExec("update issue46522 set id = id + 1;")
tk1.MustExec("commit;")

tk.MustExec("commit;")
}
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ func (s *session) retry(ctx context.Context, maxCnt uint) (err error) {
for i, sr := range nh.history {
st := sr.st
s.sessionVars.StmtCtx = sr.stmtCtx
s.sessionVars.StmtCtx.CTEStorageMap = map[int]*executor.CTEStorages{}
s.sessionVars.StmtCtx.ResetForRetry()
s.sessionVars.PreparedParams = s.sessionVars.PreparedParams[:0]
schemaVersion, err = st.RebuildPlan(ctx)
Expand Down

0 comments on commit 380a07a

Please sign in to comment.