openGauss SQL调优指南:Custom Plan和Generic Plan选择的Hint

Custom Plan和Generic Plan选择的Hint

功能描述

对于以PBE方式执行的查询语句和DML语句,优化器会基于规则、代价、参数等因素选择生成Custom Plan或Generic Plan执行。用户可以通过use_cplan/use_gplan的hint指定使用哪种计划执行方式。

语法格式

  • 指定使用Custom Plan:

    use_cplan
    
  • 指定使用Generic Plan:

    use_gplan
    

 说明:

  • 对于非PBE方式执行的SQL语句,设置本hint不会影响执行方式。
  • 本Hint的优先级仅高于基于代价的选择和plan_cache_mode参数,即plan_cache_mode无法强制选择执行方式的语句本hint也无法生效。

示例

强制使用Custom Plan

create table t (a int, b int, c int);
prepare p as select /*+ use_cplan */ * from t where a = $1;
explain execute p(1);

计划如下。可以看到过滤条件为入参的实际值,即此计划为Custom Plan。

强制使用Generic Plan

deallocate p;
prepare p as select /*+ use_gplan */ * from t where a = $1;
explain execute p(1);

计划如下。可以看到过滤条件为待填充的入参,即此计划为Generic Plan。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值