同层参数化路径的Hint

功能描述

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

语法格式

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

同层参数化路径的Hint - 图1 说明: 本参数仅在rewrite_rule中的predpushforce选项打开时生效。

示例

准备参数和表及索引:

1. openGauss=# set rewrite_rule = 'predpushforce';
2. SET
3. openGauss=# create table t1(a int, b int);
4. CREATE TABLE
5. openGauss=# create table t2(a int, b int);
6. CREATE TABLE
7. openGauss=# create index idx1 on t1(a);
8. CREATE INDEX
9. openGauss=# create index idx2 on t2(a);
10. CREATE INDEX

执行语句查看计划:

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

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

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

同层参数化路径的Hint - 图2 须知:

  • predpush_same_level可以指定多个src,但是所有的src必须在同一个条件中。
  • 如果指定的src和dest条件不存在,或该条件不符合参数化路径要求,则本hint不生效。