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#31' and p_type not like 'LARGE PLATED%' and p_size in (31, 5, 4, 13, 46, 47, 28, 42) 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=416473.86..416543.37 rows=27801 width=40) (actual time=11994.148..11997.994 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=176033 read=36409 written=4 -> GroupAggregate (cost=406730.17..414421.75 rows=27801 width=40) (actual time=11203.912..11939.923 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=176019 read=36409 written=4 -> Sort (cost=406730.17..408212.88 rows=593086 width=40) (actual time=11203.825..11377.631 rows=1189195 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 142058kB Buffers: shared hit=176019 read=36409 written=4 -> Hash Join (cost=57970.64..349859.50 rows=593086 width=40) (actual time=1767.763..7957.962 rows=1189195 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=176019 read=36409 written=4 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.885..4183.302 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=149651 read=21363 written=4 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.050..0.809 rows=56 loops=1) Buffers: shared read=56 -> Hash (cost=54247.63..54247.63 rows=296543 width=40) (actual time=1764.201..1764.201 rows=297466 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25653kB Buffers: shared hit=26368 read=15046 -> Bitmap Heap Scan on part (cost=5734.80..54247.63 rows=296543 width=40) (actual time=160.112..1527.968 rows=297466 loops=1) Recheck Cond: (p_size = ANY ('{31,5,4,13,46,47,28,42}'::integer[])) Filter: ((p_brand <> 'Brand#31'::bpchar) AND ((p_type)::text !~~ 'LARGE PLATED%'::text)) Rows Removed by Filter: 23112 Heap Blocks: exact=40514 Buffers: shared hit=26368 read=15046 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5660.67 rows=319633 width=0) (actual time=148.140..148.140 rows=320578 loops=1) Index Cond: (p_size = ANY ('{31,5,4,13,46,47,28,42}'::integer[])) Buffers: shared hit=37 read=863 Planning time: 3.345 ms Execution time: 12016.537 ms (35 rows) COMMIT; COMMIT