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#55' and p_type not like 'SMALL ANODIZED%' and p_size in (27, 33, 20, 32, 49, 9, 5, 38) 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=416644.22..416713.86 rows=27853 width=40) (actual time=10077.864..10080.895 rows=27840 loops=1) Sort Key: (count(DISTINCT partsupp.ps_suppkey)), part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 2968kB Buffers: shared hit=167448 read=44992 written=625 -> GroupAggregate (cost=406882.02..414587.90 rows=27853 width=40) (actual time=9312.563..10024.341 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=167434 read=44992 written=625 -> Sort (cost=406882.02..408367.49 rows=594188 width=40) (actual time=9312.486..9468.752 rows=1187977 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141963kB Buffers: shared hit=167434 read=44992 written=625 -> Hash Join (cost=57997.85..349897.73 rows=594188 width=40) (actual time=1481.657..6518.084 rows=1187977 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=167434 read=44992 written=625 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.474..3377.384 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=162965 read=8049 written=424 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.049..0.423 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54267.95..54267.95 rows=297094 width=40) (actual time=1051.033..1051.033 rows=297159 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25607kB Buffers: shared hit=4469 read=36943 written=201 -> Bitmap Heap Scan on part (cost=5739.62..54267.95 rows=297094 width=40) (actual time=81.574..906.735 rows=297159 loops=1) Recheck Cond: (p_size = ANY ('{27,33,20,32,49,9,5,38}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'SMALL ANODIZED%'::text)) Rows Removed by Filter: 23023 Heap Blocks: exact=40514 Buffers: shared hit=4469 read=36943 written=201 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5665.35 rows=320253 width=0) (actual time=71.417..71.417 rows=320182 loops=1) Index Cond: (p_size = ANY ('{27,33,20,32,49,9,5,38}'::integer[])) Buffers: shared hit=9 read=889 Planning time: 4.253 ms Execution time: 10098.848 ms (35 rows) COMMIT; COMMIT