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 'MEDIUM POLISHED%' and p_size in (11, 4, 47, 45, 13, 19, 38, 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=456360.92..456430.34 rows=27768 width=40) (actual time=52251.840..52258.999 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=183681 read=28767 written=16 -> GroupAggregate (cost=446629.18..454311.48 rows=27768 width=40) (actual time=50937.193..51879.503 rows=27840 loops=1) Buffers: shared hit=183665 read=28767 written=16 -> Sort (cost=446629.18..448110.10 rows=592370 width=40) (actual time=50937.106..51213.683 rows=1189963 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 142118kB Buffers: shared hit=183665 read=28767 written=16 -> Hash Join (cost=57950.63..389832.33 rows=592370 width=40) (actual time=3367.848..18879.318 rows=1189963 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=183665 read=28767 written=16 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=3.644..8453.851 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=156103 read=14912 written=16 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.058..3.560 rows=56 loops=1) Buffers: shared hit=57 -> Hash (cost=54239.84..54239.84 rows=296185 width=40) (actual time=3363.869..3363.869 rows=297659 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21532kB Buffers: shared hit=27562 read=13855 -> Bitmap Heap Scan on part (cost=5732.01..54239.84 rows=296185 width=40) (actual time=259.883..3117.592 rows=297659 loops=1) Recheck Cond: (p_size = ANY ('{11,4,47,45,13,19,38,42}'::integer[])) Filter: ((p_brand <> 'Brand#54'::bpchar) AND ((p_type)::text !~~ 'MEDIUM POLISHED%'::text)) Rows Removed by Filter: 22678 Buffers: shared hit=27562 read=13855 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5657.97 rows=319433 width=0) (actual time=243.698..243.698 rows=320337 loops=1) Index Cond: (p_size = ANY ('{11,4,47,45,13,19,38,42}'::integer[])) Buffers: shared hit=164 read=737 Total runtime: 52274.801 ms (32 rows) COMMIT; COMMIT