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#54' and p_type not like 'LARGE PLATED%' and p_size in (21, 16, 50, 35, 49, 43, 19, 11) 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=455898.53..455967.63 rows=27638 width=40) (actual time=47517.626..47519.451 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=169939 read=42505 -> GroupAggregate (cost=446213.30..453859.63 rows=27638 width=40) (actual time=46357.534..47179.021 rows=27840 loops=1) Buffers: shared hit=169923 read=42505 -> Sort (cost=446213.30..447687.29 rows=589596 width=40) (actual time=46357.391..46615.905 rows=1185562 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141775kB Buffers: shared hit=169923 read=42505 -> Hash Join (cost=57848.43..389702.39 rows=589596 width=40) (actual time=3042.582..16385.967 rows=1185562 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=169923 read=42505 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.603..6423.293 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=158530 read=12485 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.096..1.517 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54154.97..54154.97 rows=294798 width=40) (actual time=3040.336..3040.336 rows=296550 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21493kB Buffers: shared hit=11393 read=30020 -> Bitmap Heap Scan on part (cost=5690.65..54154.97 rows=294798 width=40) (actual time=219.518..2808.941 rows=296550 loops=1) Recheck Cond: (p_size = ANY ('{21,16,50,35,49,43,19,11}'::integer[])) Filter: ((p_brand <> 'Brand#54'::bpchar) AND ((p_type)::text !~~ 'LARGE PLATED%'::text)) Rows Removed by Filter: 23206 Buffers: shared hit=11393 read=30020 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5616.95 rows=317693 width=0) (actual time=202.120..202.120 rows=319756 loops=1) Index Cond: (p_size = ANY ('{21,16,50,35,49,43,19,11}'::integer[])) Buffers: shared hit=12 read=886 Total runtime: 47540.199 ms (32 rows) COMMIT; COMMIT