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: fix panic when storing outdated plans from plan cache (#19296) #20246

Merged
merged 6 commits into from
Oct 14, 2020
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
32 changes: 32 additions & 0 deletions executor/explainfor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,38 @@ func (s *testPrepareSerialSuite) TestExplainForConnPlanCache(c *C) {
wg.Wait()
}

func (s *testPrepareSerialSuite) TestSavedPlanPanicPlanCache(c *C) {
orgEnable := core.PreparedPlanCacheEnabled()
defer func() {
core.SetPreparedPlanCache(orgEnable)
}()
core.SetPreparedPlanCache(true)

var err error
tk := testkit.NewTestKit(c, s.store)
tk.Se, err = session.CreateSession4TestWithOpt(s.store, &session.Opt{
PreparedPlanCache: kvcache.NewSimpleLRUCache(100, 0.1, math.MaxUint64),
})
c.Assert(err, IsNil)

tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int generated always as (a+b) stored)")
tk.MustExec("insert into t(a,b) values(1,1)")
tk.MustExec("begin")
tk.MustExec("update t set b = 2 where a = 1")
tk.MustExec("prepare stmt from 'select b from t where a > ?'")
tk.MustExec("set @p = 0")
tk.MustQuery("execute stmt using @p").Check(testkit.Rows(
"2",
))
tk.MustExec("set @p = 1")
tk.MustQuery("execute stmt using @p").Check(testkit.Rows())
err = tk.ExecToErr("insert into t(a,b,c) values(3,3,3)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:3105]The value specified for generated column 'c' in table 't' is not allowed.")
}

func (s *testPrepareSerialSuite) TestExplainDotForExplainPlan(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte, maxExecu
MaxExecutionTime: maxExecutionTime,
}
_, pi.Digest = s.sessionVars.StmtCtx.SQLDigest()
s.currentPlan = nil
if s.sessionVars.User != nil {
pi.User = s.sessionVars.User.Username
pi.Host = s.sessionVars.User.Hostname
Expand Down