PostgreSQL查询计划中的路径-BitmapHeapPath-辨析(二)

create table t5(a int, b int);
create table t6(a int, b int);
insert into t5 values(generate_series(1,10000,1), generate_series(2,20000,2));
insert into t6 values(generate_series(1,10000,1), generate_series(2,20000,2));
create unique index I_t5 on t5 (a);
create unique index I_t6 on t6 (b);

test=# explain select V1.a, V2.b from t5 V1, t6 v2 where (V1.a=V2.b and V1.b=V2.
a) or (V1.a=5000 and V2.b=5000);
                                       QUERY PLAN

-----------------------------------------------------------------------------------------
 Nested Loop  (cost=0.54..46164.00 rows=2 width=8)
   Join Filter: (((v1.a = v2.b) AND (v1.b = v2.a)) OR ((v1.a = 5000) AND (v2.b = 5000)))
   ->  Seq Scan on t5 v1  (cost=0.00..145.00 rows=10000 width=8)
   ->  Bitmap Heap Scan on t6 v2  (cost=0.54..4.56 rows=2 width=8)
         Recheck Cond: ((v1.a = b) OR (b = 5000))
         ->  BitmapOr  (cost=0.54..0.54 rows=2 width=0)
               ->  Bitmap Index Scan on i_t6  (cost=0.00..0.27 rows=1 width=0)
                     Index Cond: (v1.a = b)
               ->  Bitmap Index Scan on i_t6  (cost=0.00..0.27 rows=1 width=0)
                     Index Cond: (b = 5000)
(10 rows)


test=# explain select V1.a, V2.b from t5 V1, t6 v2 where (V1.a=V2.b or V1.b=V2.a
) and (V1.a=5000 or V2.b=5000);
                                       QUERY PLAN

----------------------------------------------------------------------------------------
 Nested Loop  (cost=0.00..2250315.00 rows=4 width=8)
   Join Filter: (((v1.a = v2.b) OR (v1.b = v2.a)) AND ((v1.a = 5000) OR (v2.b =5000)))
   ->  Seq Scan on t5 v1  (cost=0.00..145.00 rows=10000 width=8)
   ->  Materialize  (cost=0.00..195.00 rows=10000 width=8)
         ->  Seq Scan on t6 v2  (cost=0.00..145.00 rows=10000 width=8)
(5 rows)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值