From 037cb5ee0c69a35654820efbf539dd9a3155cb2e Mon Sep 17 00:00:00 2001 From: lawyerphx Date: Tue, 16 Jun 2020 21:51:11 -0700 Subject: [PATCH] fix bug --- planner/core/prepare_test.go | 37 +++++++++++++++++++++++++++ util/stmtsummary/statement_summary.go | 2 ++ 2 files changed, 39 insertions(+) diff --git a/planner/core/prepare_test.go b/planner/core/prepare_test.go index 33909ebeb94d9..46951c9d61f74 100644 --- a/planner/core/prepare_test.go +++ b/planner/core/prepare_test.go @@ -751,6 +751,43 @@ func (s *testPlanSerialSuite) TestPlanCacheUnsignedHandleOverflow(c *C) { tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) } +func (s *testPlanSerialSuite) TestIssue18066(c *C) { + defer testleak.AfterTest(c)() + store, dom, err := newStoreWithBootstrap() + c.Assert(err, IsNil) + tk := testkit.NewTestKit(c, store) + orgEnable := core.PreparedPlanCacheEnabled() + defer func() { + dom.Close() + store.Close() + core.SetPreparedPlanCache(orgEnable) + }() + core.SetPreparedPlanCache(true) + + tk.Se, err = session.CreateSession4TestWithOpt(store, &session.Opt{ + PreparedPlanCache: kvcache.NewSimpleLRUCache(100, 0.1, math.MaxUint64), + }) + c.Assert(err, IsNil) + tk.GetConnectionID() + c.Assert(tk.Se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil), IsTrue) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int)") + tk.MustExec("prepare stmt from 'select * from t'") + tk.MustQuery("execute stmt").Check(testkit.Rows()) + tk.MustQuery("select EXEC_COUNT,plan_cache_hits, plan_in_cache from information_schema.statements_summary where digest_text='select * from t'").Check( + testkit.Rows("1 0 0")) + tk.MustQuery("execute stmt").Check(testkit.Rows()) + tk.MustQuery("select EXEC_COUNT,plan_cache_hits, plan_in_cache from information_schema.statements_summary where digest_text='select * from t'").Check( + testkit.Rows("2 1 1")) + tk.MustExec("prepare stmt from 'select * from t'") + tk.MustQuery("execute stmt").Check(testkit.Rows()) + tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) + tk.MustQuery("select EXEC_COUNT,plan_cache_hits, plan_in_cache from information_schema.statements_summary where digest_text='select * from t'").Check( + testkit.Rows("3 1 0")) +} + func (s *testPrepareSuite) TestPrepareForGroupByMultiItems(c *C) { defer testleak.AfterTest(c)() store, dom, err := newStoreWithBootstrap() diff --git a/util/stmtsummary/statement_summary.go b/util/stmtsummary/statement_summary.go index 54feab79d67ea..f9e3784bfa4e2 100644 --- a/util/stmtsummary/statement_summary.go +++ b/util/stmtsummary/statement_summary.go @@ -734,6 +734,8 @@ func (ssElement *stmtSummaryByDigestElement) add(sei *StmtExecInfo, intervalSeco if sei.PlanInCache { ssElement.planInCache = true ssElement.planCacheHits += 1 + } else { + ssElement.planInCache = false } // other