QUERY PLAN ---------------------------------------------------------------------------------- Merge Join (cost=6385.49..6829.49 rows=2880000 width=8) Merge Cond: (tab3.k = b.j) -> Sort (cost=6216.75..6222.75 rows=2400 width=8) Sort Key: tab3.k -> Nested Loop (cost=40.00..6082.00 rows=2400 width=8) -> HashAggregate (cost=40.00..42.00 rows=200 width=4) -> Seq Scan on tab3 (cost=0.00..34.00 rows=2400 width=4) -> Materialize (cost=0.00..46.00 rows=2400 width=4) -> Seq Scan on tab1 a (cost=0.00..34.00 rows=2400 width=4) -> Sort (cost=168.75..174.75 rows=2400 width=4) Sort Key: b.j -> Seq Scan on tab2 b (cost=0.00..34.00 rows=2400 width=4) (12 rows) QUERY PLAN ---------------------------------------------------------------------------------- Merge Join (cost=6385.49..6829.49 rows=2880000 width=8) Merge Cond: (tab3.k = a.i) -> Sort (cost=6216.75..6222.75 rows=2400 width=8) Sort Key: tab3.k -> Nested Loop (cost=40.00..6082.00 rows=2400 width=8) -> HashAggregate (cost=40.00..42.00 rows=200 width=4) -> Seq Scan on tab3 (cost=0.00..34.00 rows=2400 width=4) -> Materialize (cost=0.00..46.00 rows=2400 width=4) -> Seq Scan on tab2 b (cost=0.00..34.00 rows=2400 width=4) -> Sort (cost=168.75..174.75 rows=2400 width=4) Sort Key: a.i -> Seq Scan on tab1 a (cost=0.00..34.00 rows=2400 width=4) (12 rows) QUERY PLAN -------------------------------------------------------------------------------------- Nested Loop Left Join (cost=44.50..36148.50 rows=2880000 width=8) -> Seq Scan on tab1 a (cost=0.00..34.00 rows=2400 width=4) -> Materialize (cost=44.50..117.50 rows=1200 width=4) -> Hash Join (cost=44.50..111.50 rows=1200 width=4) Hash Cond: (b.j = tab3.k) -> Seq Scan on tab2 b (cost=0.00..34.00 rows=2400 width=4) -> Hash (cost=42.00..42.00 rows=200 width=4) -> HashAggregate (cost=40.00..42.00 rows=200 width=4) -> Seq Scan on tab3 (cost=0.00..34.00 rows=2400 width=4) (9 rows) QUERY PLAN ----------------------------------------------------------------------- Nested Loop Left Join (cost=0.00..115372874.00 rows=2880000 width=8) Join Filter: (SubPlan 1) -> Seq Scan on tab1 a (cost=0.00..34.00 rows=2400 width=4) -> Materialize (cost=0.00..46.00 rows=2400 width=4) -> Seq Scan on tab2 b (cost=0.00..34.00 rows=2400 width=4) SubPlan 1 -> Seq Scan on tab3 (cost=0.00..40.00 rows=12 width=4) Filter: (k = a.i) (8 rows) QUERY PLAN ----------------------------------------------------------------------- Nested Loop Left Join (cost=0.00..115372874.00 rows=2880000 width=8) Join Filter: (SubPlan 1) -> Seq Scan on tab1 a (cost=0.00..34.00 rows=2400 width=4) -> Materialize (cost=0.00..46.00 rows=2400 width=4) -> Seq Scan on tab2 b (cost=0.00..34.00 rows=2400 width=4) SubPlan 1 -> Seq Scan on tab3 (cost=0.00..40.00 rows=12 width=4) Filter: (k = b.j) (8 rows)