PostgreSQL 14 pg_prepared_statements 新增统计软/硬解析次数
PostgreSQL 中 prepare statement 可以用来 cache plan,用来减少 plan 的次数。
默认是前 5 次调用生成 custom plan,然后生成 generic plan。
PG14 中在 pg_prepared_statements 视图中新增了 generic_plans 和 custom_plans 两列,用来统计 generic plan 和 custom plan 的次数。
bill@bill=>PREPARE pr1 AS SELECT * FROM pg_class WHERE
bill-# relname = $1;
PREPARE
bill@bill=>EXECUTE pr1('t1');
bill@bill=>select * from pg_prepared_statements;
name | statement | prepare_time | parameter_types | from_sql | generic_plans | custom_plans
------+--------------------------------------------------+-------------------------------+-----------------+----------+---------------+--------------
pr1 | PREPARE pr1 AS SELECT * FROM pg_class WHERE +| 2021-05-13 10:17:28.429238+08 | {name} | t | 0 | 1
| relname = $1; | | | | |
(1 row)
执行多次后再查看:
bill@bill=>select * from pg_prepared_statements;
-[ RECORD 1 ]---+-------------------------------------------------
name | pr1
statement | PREPARE pr1 AS SELECT * FROM pg_class WHERE +
| relname = $1;
prepare_time | 2021-05-13 10:17:28.429238+08
parameter_types | {name}
from_sql | t
generic_plans | 2
custom_plans | 5
