mifar07=# EXPLAIN ANALYZE SELECT id FROM ids WHERE id IN (SELECT id FROM object_t); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------- Nested Loop IN Join (cost=0.00..9851.68 rows=2140 width=4) (actual time=0.069..97.567 rows=1934 loops=1) -> Seq Scan on ids (cost=0.00..31.40 rows=2140 width=4) (actual time=0.012..1.868 rows=2000 loops=1) -> Index Scan using object_t_pkey on object_t (cost=0.00..4.58 rows=1 width=4) (actual time=0.045..0.045 rows=1 loops=2000) Index Cond: ("outer".id = object_t.id) Total runtime: 98.236 ms (5 rows) Time: 99.921 ms mifar07=# EXPLAIN ANALYZE SELECT id FROM ids WHERE EXISTS (SELECT id FROM object_t o WHERE o.id = ids.id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- Seq Scan on ids (cost=0.00..9824.93 rows=1070 width=4) (actual time=0.071..74.158 rows=1934 loops=1) Filter: (subplan) SubPlan -> Index Scan using object_t_pkey on object_t o (cost=0.00..4.58 rows=1 width=4) (actual time=0.013..0.013 rows=1 loops=2000) Index Cond: (id = $0) Total runtime: 74.798 ms (6 rows) Time: 86.287 ms mifar07=# EXPLAIN ANALYZE SELECT id FROM ids WHERE id NOT IN (SELECT id FROM object_t); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Seq Scan on ids (cost=36410.51..36447.26 rows=1070 width=4) (actual time=4024.613..4028.774 rows=66 loops=1) Filter: (NOT (hashed subplan)) SubPlan -> Seq Scan on object_t (cost=0.00..34381.81 rows=811481 width=4) (actual time=0.040..2503.374 rows=811481 loops=1) Total runtime: 4122.327 ms (5 rows) Time: 4134.659 ms mifar07=# EXPLAIN ANALYZE SELECT id FROM ids WHERE NOT EXISTS (SELECT id FROM object_t o WHERE o.id = ids.id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- Seq Scan on ids (cost=0.00..9824.93 rows=1070 width=4) (actual time=0.220..92.611 rows=66 loops=1) Filter: (NOT (subplan)) SubPlan -> Index Scan using object_t_pkey on object_t o (cost=0.00..4.58 rows=1 width=4) (actual time=0.043..0.043 rows=1 loops=2000) Index Cond: (id = $0) Total runtime: 92.743 ms (6 rows) Time: 94.190 ms mifar07=#