PostgreSQL 12 preview - plan_cache_mode参数控制强制使用plan cache或强制custom plan (force_custom_plan and force...

标签

PostgreSQL , plan_cache_mode


背景

plan cache在OLTP中,可以大幅降低生成sql parser, 执行计划的开销。

但是在某些场景中,plan cache可能成为问题,比如AP类型的场景中,由于SQL 输入条件的变化(通常AP业务涉及的条件可能比较容易出现这样的问题),可能导致plan cache并不是最佳的执行计划。

PostgreSQL 12开放了一个参数plan_cache_mode,允许用户使用强制custom plan或者强制使用plan cache,或自动模式(默认)。

强制plan cache,类似于oracle的cursor_sharing = force。

强制custom plan,可用在plan cache执行计划不准的场景。

参考

https://www.postgresql.org/docs/devel/static/runtime-config-query.html#RUNTIME-CONFIG-QUERY-OTHER

plan_cache_mode (enum)  
  
Prepared statements (either explicitly prepared or implicitly generated,   
for example in PL/pgSQL) can be executed using custom or generic plans.   
  
A custom plan is replanned for a new parameter value,   
a generic plan is reused for repeated executions of the prepared statement.   
  
The choice between them is normally made automatically.   
This setting overrides the default behavior and forces either a custom or a generic plan.   
This can be used to work around performance problems in specific cases.   
  
Note, however, that the plan cache behavior is subject to change,   
so this setting, like all settings that force the planner's hand, should be reevaluated regularly.  
  
The allowed values are auto, force_custom_plan and force_generic_plan.   
The default value is auto. The setting is applied when a cached plan is to be executed, not when it is prepared.  

《执行计划选择算法 与 绑定变量 - PostgreSQL prepared statement: SPI_prepare, prepare|execute COMMAND, PL/pgsql STYLE: custom & generic plan cache》

《PostgreSQL 11 preview - 增加强制custom plan GUC开关(plancache_mode),对付倾斜》

《PostgreSQL 11 preview - 强制auto prepared statment开关(自动化plan cache)(类似Oracle cursor_sharing force)》

《PostgreSQL 商用版本EPAS(阿里云ppas(Oracle 兼容版)) 自定义custom plan次数》

《PostgreSQL Oracle 兼容性之 - SQL OUTLINE插件sr_plan (保存、篡改、固定 执行计划)》

《官人要杯咖啡吗? - PostgreSQL实时监测PLAN tree的执行进度 - pg_query_state》

《PostgreSQL plan cache 源码浅析 - 如何确保不会计划倾斜》

《PostgreSQL 特性分析 Plan Hint》

《阿里云 PostgreSQL pg_hint_plan插件的用法》

《PostgreSQL SQL HINT的使用(pg_hint_plan)》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值