QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Merge Join (cost=xxx rows=10 width=4) Merge Cond: (bmt1.c1 = bmt2.c1) CTE c1 -> Nested Loop (cost=xxx rows=100 width=4) Join Filter: (b1t2.c1 = b1t1.c1) -> Hash Join (cost=xxx rows=100 width=12) Hash Cond: (b1t3.c1 = b1t2.c1) -> Merge Join (cost=xxx rows=1100 width=8) Merge Cond: (b1t3.c1 = b1t4.c1) -> Index Only Scan using t3_i1 on t3 b1t3 (cost=xxx rows=1100 width=4) -> Index Only Scan using t4_i1 on t4 b1t4 (cost=xxx rows=1100 width=4) -> Hash (cost=xxx rows=100 width=4) -> Seq Scan on t2 b1t2 (cost=xxx rows=100 width=4) -> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx rows=1 width=4) Index Cond: (c1 = b1t3.c1) InitPlan 2 (returns $2) -> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx rows=1 width=4) Index Cond: (c1 = 1) InitPlan 3 (returns $3) -> Seq Scan on t1 b3t1 (cost=xxx rows=1000 width=4) -> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx rows=999 width=4) Filter: (c1 <> $3) -> Sort (cost=xxx rows=100 width=16) Sort Key: bmt2.c1 -> Nested Loop (cost=xxx rows=100 width=16) -> Hash Join (cost=xxx rows=100 width=12) Hash Cond: (bmt3.c1 = bmt4.c1) -> Seq Scan on t3 bmt3 (cost=xxx rows=1100 width=4) -> Hash (cost=xxx rows=100 width=8) -> Merge Join (cost=xxx rows=100 width=8) Merge Cond: (bmt4.c1 = c1.c1) -> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx rows=1100 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: c1.c1 -> CTE Scan on c1 (cost=xxx rows=100 width=4) -> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx rows=1 width=4) Index Cond: (c1 = bmt3.c1) (37 rows) QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Merge Join (cost=xxx rows=1 width=4) Merge Cond: (bmt1.c1 = bmt2.c1) CTE c1 -> Nested Loop (cost=xxx rows=1 width=4) Join Filter: (b1t2.c1 = b1t1.c1) -> Hash Join (cost=xxx rows=1 width=12) Hash Cond: (b1t3.c1 = b1t2.c1) -> Merge Join (cost=xxx rows=1 width=8) Merge Cond: (b1t3.c1 = b1t4.c1) -> Index Only Scan using t3_i1 on t3 b1t3 (cost=xxx rows=1100 width=4) -> Index Only Scan using t4_i1 on t4 b1t4 (cost=xxx rows=1100 width=4) -> Hash (cost=xxx rows=100 width=4) -> Seq Scan on t2 b1t2 (cost=xxx rows=100 width=4) -> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx rows=1 width=4) Index Cond: (c1 = b1t3.c1) InitPlan 2 (returns $2) -> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx rows=1 width=4) Index Cond: (c1 = 1) InitPlan 3 (returns $3) -> Seq Scan on t1 b3t1 (cost=xxx rows=1000 width=4) -> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx rows=999 width=4) Filter: (c1 <> $3) -> Sort (cost=xxx rows=1 width=16) Sort Key: bmt2.c1 -> Nested Loop (cost=xxx rows=1 width=16) -> Hash Join (cost=xxx rows=1 width=12) Hash Cond: (bmt3.c1 = bmt4.c1) -> Seq Scan on t3 bmt3 (cost=xxx rows=1100 width=4) -> Hash (cost=xxx rows=1 width=8) -> Merge Join (cost=xxx rows=1 width=8) Merge Cond: (bmt4.c1 = c1.c1) -> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx rows=1100 width=4) -> Sort (cost=xxx rows=1 width=4) Sort Key: c1.c1 -> CTE Scan on c1 (cost=xxx rows=1 width=4) -> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx rows=1 width=4) Index Cond: (c1 = bmt3.c1) (37 rows)