Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: reset CTEStorageMap before txn conflict and retry() (#49399) #49446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,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 pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,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.PlanCacheParams.Reset()
schemaVersion, err = st.RebuildPlan(ctx)
Expand Down