Results from the working setup (Listing B) ========================================== id ----- 500 600 (2 rows) QUERY PLAN -------------------------------------------------------------------------------- Hash Left Join (cost=473.04..756.38 rows=14 width=4) Hash Cond: (public.items.id = public.items.id) Filter: (public.items.id IS NULL) -> Seq Scan on items (cost=0.00..161.70 rows=10670 width=4) -> Hash (cost=472.38..472.38 rows=53 width=4) -> Hash Left Join (cost=189.04..472.38 rows=53 width=4) Hash Cond: (public.items.id = public.items.id) Filter: (public.items.id IS NULL) -> Seq Scan on items (cost=0.00..161.70 rows=10670 width=4) -> Hash (cost=188.38..188.38 rows=53 width=4) -> Seq Scan on items (cost=0.00..188.38 rows=53 width=4) Filter: (number = 1) (12 rows) Test Query under the faulty setup (Listing C) ============================================= id ---- (0 rows) QUERY PLAN ------------------------------------------------------------------------------ Nested Loop Left Join (cost=476.90..1099.08 rows=1 width=4) Filter: (public.items.id IS NULL) -> Hash Left Join (cost=476.90..1079.30 rows=50 width=8) Hash Cond: (public.items.id = public.items.id) Filter: (public.items.id IS NULL) -> Seq Scan on items (cost=0.00..351.40 rows=10040 width=4) -> Hash (cost=351.40..351.40 rows=10040 width=4) -> Seq Scan on items (cost=0.00..351.40 rows=10040 width=4) -> Index Scan using items_pkey on items (cost=0.00..0.38 rows=1 width=4) Index Cond: (public.items.id = public.items.id) Filter: (number = 1) (11 rows)