Skip to content

Commit

Permalink
cherry pick #19296 to release-4.0 (#20246)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>

Co-authored-by: Kenan Yao <[email protected]>
  • Loading branch information
ti-srebot and eurekaka authored Oct 14, 2020
1 parent bab4a1d commit 84b22ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 84b22ca

Please sign in to comment.