diff --git a/planner/core/plan_cache.go b/planner/core/plan_cache.go index cbe16438ba8c3..98b49c1bcc452 100644 --- a/planner/core/plan_cache.go +++ b/planner/core/plan_cache.go @@ -127,7 +127,7 @@ func GetPlanFromSessionPlanCache(ctx context.Context, sctx sessionctx.Context, sessVars := sctx.GetSessionVars() stmtCtx := sessVars.StmtCtx stmtAst := stmt.PreparedAst - stmtCtx.UseCache = true + stmtCtx.UseCache = stmt.StmtCacheable if !stmt.StmtCacheable { stmtCtx.SetSkipPlanCache(errors.Errorf("skip plan-cache: %s", stmt.UncacheableReason)) } diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 05fc7d338a850..8acc28b7b0062 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -503,18 +503,3 @@ func TestPlanCacheWithLimit(t *testing.T) { tk.MustExec("execute stmt using @a") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: limit count more than 10000")) } - -func TestUncacheableReason(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - - tk.MustExec("prepare st from 'select /*+ ignore_plan_cache() */ * from t'") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: ignore plan cache by hint")) - tk.MustExec("execute st") // show the un-cacheable reason when executing the statement - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: ignore plan cache by hint")) - tk.MustExec("execute st") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -}