更新时间:2024-07-03 GMT+08:00
同层参数化路径的Hint
语法格式
1 2 |
predpush_same_level(src, dest) predpush_same_level(src1 src2 ..., dest) |
本参数仅在rewrite_rule中的predpushforce选项打开时生效。
示例
准备参数和表及索引:
1 2 3 4 5 6 7 8 9 10 |
openGauss=# set rewrite_rule = 'predpushforce'; SET openGauss=# create table t1(a int, b int) distribute by hash(a); CREATE TABLE openGauss=# create table t2(a int, b int) distribute by hash(a); CREATE TABLE openGauss=# create index idx1 on t1(a); CREATE INDEX openGauss=# create index idx2 on t2(a); CREATE INDEX |
执行语句查看计划:
1 2 3 4 5 6 7 8 9 10 11 |
openGauss=# explain select * from t1, t2 where t1.a = t2.a; QUERY PLAN ----------------------------------------------------------------------- Streaming (type: GATHER) (cost=18.25..77.00 rows=1000 width=16) Node/s: All datanodes -> Hash Join (cost=14.25..30.12 rows=1000 width=16) Hash Cond: (t1.a = t2.a) -> Seq Scan on t1 (cost=0.00..9.00 rows=1000 width=8) -> Hash (cost=8.00..8.00 rows=1000 width=8) -> Seq Scan on t2 (cost=0.00..8.00 rows=1000 width=8) (7 rows) |
可以看到t1.a = t2.a条件过滤在Join上面,此时可以通过predpush_same_level(t1, t2)将条件下推至t2的扫描算子上:
1 2 3 4 5 6 7 8 9 10 |
openGauss=# explain select /*+predpush_same_level(t1, t2)*/ * from t1, t2 where t1.a = t2.a; QUERY PLAN --------------------------------------------------------------------------- Streaming (type: GATHER) (cost=4.00..263.88 rows=1000 width=16) Node/s: All datanodes -> Nested Loop (cost=0.00..217.00 rows=1000 width=16) -> Seq Scan on t1 (cost=0.00..9.00 rows=1000 width=8) -> Index Scan using idx2 on t2 (cost=0.00..0.41 rows=1 width=8) Index Cond: (a = t1.a) (6 rows) |
- predpush_same_level可以指定多个src,但是所有的src必须在同一个条件中。
- 如果指定的src和dest条件不存在,或该条件不符合参数化路径要求,则本hint不生效。
- 如果dest扫描算子上存在stream算子,则本hint不生效。
父主题: 使用Plan Hint进行调优