SELECT COUNT(*) FROM Border_Shop_List WHERE 'Quantum_' || Border_Shop_List.Assignment_ID || '_' || Border_Shop_List.Assignment_Year || '_' || Border_Shop_List.Evaluation_ID NOT IN (SELECT Foreign_Key FROM Sample WHERE Foreign_Key IS NOT NULL) 7.3.2 neo=# explain analyze SELECT COUNT(*) FROM Border_Shop_List WHERE 'Quantum_' || Border_Shop_List.Assignment_ID || '_' || Border_Shop_List.Assignment_Year || '_' || Border_Shop_List.Evaluation_ID NOT IN (SELECT Foreign_Key FROM Sample WHERE Foreign_Key IS NOT NULL); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Aggregate (cost=2460448.75..2460448.75 rows=1 width=0) (actual time=16500.14..16500.14 rows=1 loops=1) -> Seq Scan on border_shop_list (cost=0.00..2460447.50 rows=500 width=0) (actual time=3245.59..16500.11 rows=3 loops=1) Filter: (subplan) SubPlan -> Materialize (cost=2460.41..2460.41 rows=2741 width=34) (actual time=0.02..0.45 rows=1533 loops=3065) -> Seq Scan on sample (cost=0.00..2460.41 rows=2741 width=34) (actual time=41.89..50.75 rows=3062 loops=1) Filter: (foreign_key IS NOT NULL) Total runtime: 16500.83 msec (8 rows) 7.2.1 neo=# explain SELECT COUNT(*) FROM Border_Shop_List WHERE 'Quantum_' || Border_Shop_List.Assignment_ID || ' _' || Border_Shop_List.Assignment_Year || '_' || Border_Shop_List.Evaluation_ID NOT IN (SELECT Foreign_Key FROM Sample WHERE Foreign_Key IS NOT NULL); NOTICE: QUERY PLAN: Aggregate (cost=11323743.75..11323743.75 rows=1 width=0) -> Seq Scan on border_shop_list (cost=0.00..11323742.50 rows=500 width=0) SubPlan -> Seq Scan on sample (cost=0.00..22647.41 rows=33457 width=34) EXPLAIN