Prepare 语句执行计划缓存不支持CTE

【 TiDB 使用环境】生产环境
【 TiDB 版本】
【复现路径】做过哪些操作出现的问题
【遇到的问题:问题现象及影响】
【资源配置】
背景:线上有慢查,生成执行计划耗时比较大,如下

就已开启了prepared-plan-cache.enabled
测试了一下,prepare/stmt不支持CTE

CREATE TABLE `a` (
  `name` varchar(20) DEFAULT NULL,
  `v_int` int(11) DEFAULT NULL,
  `v_decimal` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

insert into a values("a",18,100),("b",19,200),("c",20,300);
mysql>prepare stmt1 from 'with tmpa as (select name from a where name =?) select * from tmpa';
Query OK, 0 rows affected (0.00 sec)
mysql>prepare stmt2 from 'select name from (select name from a where name =?) tmpa';
Query OK, 0 rows affected (0.00 sec)
mysql> set @user="a" ;
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt1 using @user;
+------+
| name |
+------+
| a    |
+------+
1 row in set (0.01 sec)

mysql> execute stmt1 using @user;
+------+
| name |
+------+
| a    |
+------+
1 row in set (0.00 sec)

mysql> select @@last_plan_from_cache;
+------------------------+
| @@last_plan_from_cache |
+------------------------+
|                      0 |
+------------------------+
1 row in set (0.00 sec)

mysql> execute stmt2 using @user;
+------+
| name |
+------+
| a    |
+------+
1 row in set (0.01 sec)

mysql> execute stmt2 using @user;
+------+
| name |
+------+
| a    |
+------+
1 row in set (0.00 sec)

mysql> select @@last_plan_from_cache;
+------------------------+
| @@last_plan_from_cache |
+------------------------+
|                      1 |
+------------------------+
1 row in set (0.00 sec)


(prepare/stmt)目前不支持CTE

1 个赞

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。