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#14' and p_type not like 'STANDARD BRUSHED%' and p_size in (40, 42, 25, 29, 14, 5, 31, 7) 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=417042.55..417112.46 rows=27964 width=40) (actual time=10617.744..10619.891 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=5624 read=206818 written=10 -> GroupAggregate (cost=407240.66..414977.23 rows=27964 width=40) (actual time=9730.688..10563.490 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=5610 read=206818 written=10 -> Sort (cost=407240.66..408732.05 rows=596554 width=40) (actual time=9730.603..9966.957 rows=1185796 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141793kB Buffers: shared hit=5610 read=206818 written=10 -> Hash Join (cost=58088.82..350012.36 rows=596554 width=40) (actual time=991.037..6546.058 rows=1185796 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=5610 read=206818 written=10 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.383..4109.891 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=5351 read=165663 written=10 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.042..0.332 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54344.13..54344.13 rows=298277 width=40) (actual time=986.652..986.652 rows=296622 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25552kB Buffers: shared hit=259 read=41155 -> Bitmap Heap Scan on part (cost=5778.96..54344.13 rows=298277 width=40) (actual time=71.350..856.209 rows=296622 loops=1) Recheck Cond: (p_size = ANY ('{40,42,25,29,14,5,31,7}'::integer[])) Filter: ((p_brand <> 'Brand#14'::bpchar) AND ((p_type)::text !~~ 'STANDARD BRUSHED%'::text)) Rows Removed by Filter: 23006 Heap Blocks: exact=40516 Buffers: shared hit=259 read=41155 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5704.39 rows=321727 width=0) (actual time=62.332..62.332 rows=319628 loops=1) Index Cond: (p_size = ANY ('{40,42,25,29,14,5,31,7}'::integer[])) Buffers: shared hit=8 read=890 Planning time: 4.221 ms Execution time: 10646.383 ms (35 rows) COMMIT; COMMIT