diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index bf2dc51efcf99..73a9ec02f40dd 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -1235,9 +1235,9 @@ func TestCTE4PlanCache(t *testing.T) { tk.MustExec("set @a=5, @b=4, @c=2, @d=1;") tk.MustQuery("execute stmt using @d, @a").Check(testkit.Rows("1", "2", "3", "4", "5")) tk.MustQuery("execute stmt using @d, @b").Check(testkit.Rows("1", "2", "3", "4")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) tk.MustQuery("execute stmt using @c, @b").Check(testkit.Rows("2", "3", "4")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) // Two seed parts. tk.MustExec("prepare stmt from 'with recursive cte1 as (" + @@ -1250,7 +1250,7 @@ func TestCTE4PlanCache(t *testing.T) { tk.MustExec("set @a=10, @b=2;") tk.MustQuery("execute stmt using @a").Check(testkit.Rows("1", "2", "2", "3", "3", "4", "4", "5", "5", "6", "6", "7", "7", "8", "8", "9", "9", "10", "10")) tk.MustQuery("execute stmt using @b").Check(testkit.Rows("1", "2", "2")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) // Two recursive parts. tk.MustExec("prepare stmt from 'with recursive cte1 as (" + @@ -1265,25 +1265,27 @@ func TestCTE4PlanCache(t *testing.T) { tk.MustExec("set @a=1, @b=2, @c=3, @d=4, @e=5;") tk.MustQuery("execute stmt using @c, @b, @e;").Check(testkit.Rows("1", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", "6", "6")) tk.MustQuery("execute stmt using @b, @a, @d;").Check(testkit.Rows("1", "2", "2", "2", "3", "3", "3", "4", "4", "4")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) tk.MustExec("drop table if exists t1;") tk.MustExec("create table t1(a int);") tk.MustExec("insert into t1 values(1);") tk.MustExec("insert into t1 values(2);") tk.MustExec("prepare stmt from 'SELECT * FROM t1 dt WHERE EXISTS(WITH RECURSIVE qn AS (SELECT a*? AS b UNION ALL SELECT b+? FROM qn WHERE b=?) SELECT * FROM qn WHERE b=a);';") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: find table test.qn failed: [schema:1146]Table 'test.qn' doesn't exist")) tk.MustExec("set @a=1, @b=2, @c=3, @d=4, @e=5, @f=0;") tk.MustQuery("execute stmt using @f, @a, @f").Check(testkit.Rows("1")) tk.MustQuery("execute stmt using @a, @b, @a").Sort().Check(testkit.Rows("1", "2")) tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) tk.MustQuery("execute stmt using @a, @b, @a").Sort().Check(testkit.Rows("1", "2")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: PhysicalApply plan is un-cacheable")) + //tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: PhysicalApply plan is un-cacheable")) tk.MustExec("prepare stmt from 'with recursive c(p) as (select ?), cte(a, b) as (select 1, 1 union select a+?, 1 from cte, c where a < ?) select * from cte order by 1, 2;';") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: find table test.cte failed: [schema:1146]Table 'test.cte' doesn't exist")) tk.MustQuery("execute stmt using @a, @a, @e;").Check(testkit.Rows("1 1", "2 1", "3 1", "4 1", "5 1")) tk.MustQuery("execute stmt using @b, @b, @c;").Check(testkit.Rows("1 1", "3 1")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) } func TestValidity4PlanCache(t *testing.T) { diff --git a/planner/core/plan_cacheable_checker.go b/planner/core/plan_cacheable_checker.go index d11cfe459bd8f..8fca84aa58809 100644 --- a/planner/core/plan_cacheable_checker.go +++ b/planner/core/plan_cacheable_checker.go @@ -639,8 +639,8 @@ func checkTableCacheable(ctx context.Context, sctx sessionctx.Context, schema in sql = sql[:256] } logutil.BgLogger().Warn("find table failed", zap.Error(err), zap.String("sql", sql), - zap.String("table_schema", node.Schema.O), zap.String("table_name", node.Name.O)) - return false, fmt.Sprintf("find table %s.%s failed: %s", node.Schema, node.Name, err.Error()) + zap.String("table_schema", tableSchema.O), zap.String("table_name", node.Name.O)) + return false, fmt.Sprintf("find table %s.%s failed: %s", tableSchema, node.Name, err.Error()) } if tb.Meta().GetPartitionInfo() != nil {