SELECT COUNT(*) FROM Border_Shop_List WHERE NOT EXISTS (SELECT Foreign_Key FROM Sample WHERE Foreign_Key='Quantum_' || Border_Shop_List.Assignment_ID || '_' || Assignment_Year || '_' || Evaluation_ID) 7.3.2 neo=# explain analyze SELECT COUNT(*) FROM Border_Shop_List WHERE NOT EXISTS (SELECT Foreign_Key FROM Sample WHERE Foreign_Key='Quantum_' || Border_Shop_List.Assignment_ID || '_' || Assignment_Year || '_' || Evaluation_ID); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------ Aggregate (cost=3959148.75..3959148.75 rows=1 width=0) (actual time=667055.64..667055.64 rows=1 loops=1) -> Seq Scan on border_shop_list (cost=0.00..3959147.50 rows=500 width=0) (actual time=110283.60..667055.60 rows=3 loops=1) Filter: (NOT (subplan)) SubPlan -> Seq Scan on sample (cost=0.00..3959.13 rows=1 width=34) (actual time=217.62..217.62 rows=1 loops=3065) Filter: ((foreign_key)::text = ((((('Quantum_'::text || ($0)::text) || '_'::text) || ($1)::text) || '_'::text) || ($2)::text)) Total runtime: 667055.79 msec (7 rows) 7.2.1 neo=# explain SELECT COUNT(*) FROM Border_Shop_List WHERE NOT EXISTS (SELECT Foreign_Key FROM Sample WHERE Foreign_Key='Quantum_' || Border_Shop_List.Assignment_ID || '_' || Assignment_Year || '_' || Evaluation_ID); NOTICE: QUERY PLAN: Aggregate (cost=5992.94..5992.94 rows=1 width=0) -> Seq Scan on border_shop_list (cost=0.00..5991.69 rows=500 width=0) SubPlan -> Index Scan using sample_foreign_key on sample (cost=0.00..5.97 rows=1 width=34) EXPLAIN