diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 43f621ab36..2cb4e0c2ad 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -1025,6 +1025,21 @@ func TestPlanCacheWithLimit(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: limit count more than 10000")) } +func TestPlanCacheMemoryTable(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`create table t1 (a int)`) + tk.MustExec(`create table t2 (a int, b int)`) + + tk.MustExec(`prepare st from 'select count(*) from information_schema.COLUMNS where table_name=?'`) + tk.MustExec(`set @a='t1'`) + tk.MustQuery(`execute st using @a`).Check(testkit.Rows("1")) // 1 column + tk.MustExec(`set @a='t2'`) + tk.MustQuery(`execute st using @a`).Check(testkit.Rows("2")) // 2 columns + tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // plan accessing memory tables cannot hit the cache +} + func TestPlanCacheWithSubquery(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/planner/core/plan_cacheable_checker.go b/planner/core/plan_cacheable_checker.go index 1bc5200fa2..b201ca7e00 100644 --- a/planner/core/plan_cacheable_checker.go +++ b/planner/core/plan_cacheable_checker.go @@ -392,6 +392,8 @@ func isPhysicalPlanCacheable(sctx sessionctx.Context, p PhysicalPlan, paramNum, } case *PhysicalShuffle, *PhysicalShuffleReceiverStub: return false, "skip plan-cache: get a Shuffle plan" + case *PhysicalMemTable: + return false, "skip plan-cache: PhysicalMemTable plan is un-cacheable" case *PhysicalIndexMergeReader: if x.AccessMVIndex { return false, "skip plan-cache: the plan with IndexMerge accessing Multi-Valued Index is un-cacheable"