更新时间:2024-02-29 GMT+08:00
分享

参数化路径的Hint

功能描述

指明参数化路径,条件谓词下推方式。

语法格式

1
2
predpush(src1 src2)
predpush(src, dest)

参数说明

  • src, src1, src2表示predpush下推candidates一侧表集合。
  • dest表示predpush下推所指定的dest表也就是目标表。
  • predpush如果没有逗号表示所有表都是candidates表, 如果有逗号就说明同时指定了candidates表和dest表。

使用predpush hint将过滤表达式尽可能移至靠近数据源的位置以达到查询优化的目的。

  • 使用predpush hint需要确保rewrite_rule GUC参数包含PREDPUSH|REDPUSHFORCE|PREDPUSHNORMAL选项。
  • subquery_block也可以是视图/物化视图。

示例

灵活使用predpush hint可以大幅提高语句的执行效率。示例如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
set rewrite_rule = 'predpushnormal';
explain (costs off) SELECT /*+PREDPUSH(t2, st3)*/ *
FROM t2,
    (SELECT sum(t3.b), t3.a FROM t3, t4 where t3.a = t4.a GROUP BY t3.a) st3
WHERE st3.a = t2.a;
 id |                      operation
----+------------------------------------------------------
  1 | ->  Streaming (type: GATHER)
  2 |    ->  Nested Loop (3,4)
  3 |       ->  Seq Scan on t2
  4 |       ->  GroupAggregate
  5 |          ->  Nested Loop (6,7)
  6 |             ->  Index Only Scan using t4_a_idx on t4
  7 |             ->  Materialize
  8 |                ->  Index Scan using t3_a_idx on t3
(8 rows)

 Predicate Information (identified by plan id)
-----------------------------------------------
   6 --Index Only Scan using t4_a_idx on t4
         Index Cond: (a = t2.a)
   8 --Index Scan using t3_a_idx on t3
         Index Cond: (a = t2.a)
(4 rows)

在未使用predpush hint的情况下,子查询中t3,t4在做join之前没有经过任何来自query block外的处理,所以返回的结果集较大,造成性能浪费。

然而,如上面计划所示,在使用了predpush hint后,t3,t4在做join之前先基于t2表进行了一次条件过滤,join后返回的结果集较小,可以有效提升性能。

分享:

    相关文档

    相关产品