ITPub博客

首页 > 数据库 > 数据库开发技术 > openGauss学习笔记-260 openGauss性能调优-使用Plan Hint进行调优-同层参数化路径的Hint

openGauss学习笔记-260 openGauss性能调优-使用Plan Hint进行调优-同层参数化路径的Hint

原创 数据库开发技术 作者:shuchaoyang 时间:2024-01-06 07:00:00 0 删除 编辑

openGauss学习笔记-260 openGauss性能调优-使用Plan Hint进行调优-同层参数化路径的Hint260.1 功能描述260.2 语法格式260.3 示例

openGauss学习笔记-260 openGauss性能调优-使用Plan Hint进行调优-同层参数化路径的Hint

260.1 功能描述

通过predpush_same_level Hint来指定同层表或物化视图之间参数化路径生成。

260.2 语法格式

predpush_same_level(src, dest)
predpush_same_level(src1 src2 ..., dest)

说明: 本参数仅在rewrite_rule中的predpushforce选项打开时生效。

260.3 示例

准备参数和表及索引:

openGauss=# set rewrite_rule = 'predpushforce';
SET
openGauss=# create table t1(a int, b int);
CREATE TABLE
openGauss=# create table t2(a int, b int);
CREATE TABLE
openGauss=# create index idx1 on t1(a);
CREATE INDEX
openGauss=# create index idx2 on t2(a);
CREATE INDEX

执行语句查看计划:

openGauss=# explain select * from t1, t2 where t1.a = t2.a;
                           QUERY PLAN
------------------------------------------------------------------
Hash Join  (cost=27.50..56.25 rows=1000 width=16)
  Hash Cond: (t1.a = t2.a)
  -> Seq Scan on t1  (cost=0.00..15.00 rows=1000 width=8)
  ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
        -> Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
(5 rows)

可以看到t1.a = t2.a条件过滤在Join上面,此时可以通过predpush_same_level(t1, t2)将条件下推至t2的扫描算子上:

openGauss=# explain select /*+predpush_same_level(t1, t2)*/ * from t1, t2 where t1.a = t2.a;
                            QUERY PLAN
---------------------------------------------------------------------
Nested Loop  (cost=0.00..335.00 rows=1000 width=16)
  -> Seq Scan on t1  (cost=0.00..15.00 rows=1000 width=8)
  ->  Index Scan using idx2 on t2  (cost=0.00..0.31 rows=1 width=8)
        Index Cond: (a = t1.a)
(4 rows)

须知:

  • predpush_same_level可以指定多个src,但是所有的src必须在同一个条件中。

  • 如果指定的src和dest条件不存在,或该条件不符合参数化路径要求,则本hint不生效。


👍 点赞,你的认可是我创作的动力!

⭐️ 收藏,你的青睐是我努力的方向!

✏️ 评论,你的意见是我进步的财富!


PS:因为公众号平台更改了推送规则,如果不想错过内容,记得读完点一下“在看”,加个“星标”,这样每次新文章推送才会第一时间出现在你的订阅列表里。点“在看”支持我吧!


原文作者:超哥的IT私房菜;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论
专注于IT系统集成、运维、架构二十年的IT职场老兵,拥有CCNA、OCA、OCP、PGCA、PGCE认证证书,公众号:超哥的IT私房菜,知识星球:超哥的IT私房菜,目前是多家IT厂商的咨询顾问。

注册时间:2021-08-27

  • 博文量
    552
  • 访问量
    303581