重庆思庄Oracle、Redhat认证学习论坛

标题: PG 查看有绑定变量的SQL执行计划 [打印本页]

作者: 郑全    时间: 2024-12-10 13:30
标题: PG 查看有绑定变量的SQL执行计划
通过

prepare p1 as select * from t1 where id = $1 and info = $2;


explain execute p1(null,null);


如果是PG12以前版本,需要执行5次才有执行计划。
PG12以后,加 plan_cache_mode 即可


bill=# prepare p1 as select * from t1 where id =$1 and info = $2;
PREPARE
bill=# set plan_cache_mode = force_generic_plan;
SET
bill=# explain execute p1(null,null);
                            QUERY PLAN
-------------------------------------------------------------------
Index Scan using t1_pkey on t1  (cost=0.15..2.77 rows=1 width=36)
   Index Cond: (id = $1)
   Filter: (info = $2)







欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2