BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt from partsupp, part where p_partkey = ps_partkey and p_brand <> 'Brand#33' and p_type not like 'STANDARD PLATED%' and p_size in (14, 12, 17, 34, 11, 25, 21, 30) and ps_suppkey not in ( select s_suppkey from supplier where s_comment like '%Customer%Complaints%' ) group by p_brand, p_type, p_size order by supplier_cnt desc, p_brand, p_type, p_size; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Sort (cost=456347.34..456416.75 rows=27766 width=40) (actual time=62556.897..62559.104 rows=27839 loops=1) Sort Key: (count(DISTINCT partsupp.ps_suppkey)), part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 2967kB Buffers: shared hit=56340 read=156104 -> GroupAggregate (cost=446616.35..454298.06 rows=27766 width=40) (actual time=61130.616..62155.984 rows=27839 loops=1) Buffers: shared hit=56324 read=156104 -> Sort (cost=446616.35..448097.16 rows=592324 width=40) (actual time=61130.496..61468.219 rows=1184932 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141725kB Buffers: shared hit=56324 read=156104 -> Hash Join (cost=57943.01..389824.25 rows=592324 width=40) (actual time=4353.225..28723.871 rows=1184932 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=56324 read=156104 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.111..15585.000 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=51845 read=119170 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.070..1.011 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54232.50..54232.50 rows=296162 width=40) (actual time=4351.783..4351.783 rows=296383 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21440kB Buffers: shared hit=4479 read=36934 -> Bitmap Heap Scan on part (cost=5730.33..54232.50 rows=296162 width=40) (actual time=250.672..4091.121 rows=296383 loops=1) Recheck Cond: (p_size = ANY ('{14,12,17,34,11,25,21,30}'::integer[])) Filter: ((p_brand <> 'Brand#33'::bpchar) AND ((p_type)::text !~~ 'STANDARD PLATED%'::text)) Rows Removed by Filter: 23041 Buffers: shared hit=4479 read=36934 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5656.29 rows=319207 width=0) (actual time=227.086..227.086 rows=319424 loops=1) Index Cond: (p_size = ANY ('{14,12,17,34,11,25,21,30}'::integer[])) Buffers: shared hit=9 read=889 Total runtime: 62591.135 ms (32 rows) COMMIT; COMMIT