QUERY PLAN -------------------------------------------------------------------------------------------- Hash Join (cost=xxx rows=10 width=4) Hash Cond: (bmt1.c1 = bmt2.c1) CTE c1 -> Merge Join (cost=xxx rows=100 width=4) Merge Cond: (b1t1.c1 = b1t2.c1) -> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b1t2.c1 -> Seq Scan on t2 b1t2 (cost=xxx rows=100 width=4) InitPlan 2 (returns $1) -> Merge Join (cost=xxx rows=100 width=4) Merge Cond: (b2t1.c1 = b2t2.c1) -> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b2t2.c1 -> Seq Scan on t2 b2t2 (cost=xxx rows=100 width=4) InitPlan 3 (returns $2) -> Merge Join (cost=xxx rows=100 width=4) Merge Cond: (b3t1.c1 = b3t2.c1) -> Index Only Scan using t1_i1 on t1 b3t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b3t2.c1 -> Seq Scan on t2 b3t2 (cost=xxx rows=100 width=4) -> Seq Scan on t1 bmt1 (cost=xxx rows=999 width=4) Filter: (c1 <> $2) -> Hash (cost=xxx rows=100 width=8) -> Merge Join (cost=xxx rows=100 width=8) Merge Cond: (bmt2.c1 = c1.c1) -> Sort (cost=xxx rows=100 width=4) Sort Key: bmt2.c1 -> Seq Scan on t2 bmt2 (cost=xxx rows=100 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: c1.c1 -> CTE Scan on c1 (cost=xxx rows=100 width=4) (34 rows) QUERY PLAN -------------------------------------------------------------------------------------------- Hash Join (cost=xxx rows=1 width=4) Hash Cond: (bmt1.c1 = bmt2.c1) CTE c1 -> Merge Join (cost=xxx rows=1 width=4) Merge Cond: (b1t1.c1 = b1t2.c1) -> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b1t2.c1 -> Seq Scan on t2 b1t2 (cost=xxx rows=100 width=4) InitPlan 2 (returns $1) -> Merge Join (cost=xxx rows=1 width=4) Merge Cond: (b2t1.c1 = b2t2.c1) -> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b2t2.c1 -> Seq Scan on t2 b2t2 (cost=xxx rows=100 width=4) InitPlan 3 (returns $2) -> Merge Join (cost=xxx rows=1 width=4) Merge Cond: (b3t1.c1 = b3t2.c1) -> Index Only Scan using t1_i1 on t1 b3t1 (cost=xxx rows=1000 width=4) -> Sort (cost=xxx rows=100 width=4) Sort Key: b3t2.c1 -> Seq Scan on t2 b3t2 (cost=xxx rows=100 width=4) -> Seq Scan on t1 bmt1 (cost=xxx rows=999 width=4) Filter: (c1 <> $2) -> Hash (cost=xxx rows=1 width=8) -> Merge Join (cost=xxx rows=1 width=8) Merge Cond: (bmt2.c1 = c1.c1) -> Sort (cost=xxx rows=100 width=4) Sort Key: bmt2.c1 -> Seq Scan on t2 bmt2 (cost=xxx rows=100 width=4) -> Sort (cost=xxx rows=1 width=4) Sort Key: c1.c1 -> CTE Scan on c1 (cost=xxx rows=1 width=4) (34 rows)