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#13' and p_type not like 'SMALL BURNISHED%' and p_size in (19, 3, 25, 21, 18, 24, 40, 34) 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=456413.46..456482.94 rows=27789 width=40) (actual time=47923.744..47927.340 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=112727 read=99717 written=7734 -> GroupAggregate (cost=446674.11..454362.33 rows=27789 width=40) (actual time=46635.419..47566.257 rows=27839 loops=1) Buffers: shared hit=112711 read=99717 written=7734 -> Sort (cost=446674.11..448156.18 rows=592826 width=40) (actual time=46635.290..46928.335 rows=1185466 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141767kB Buffers: shared hit=112711 read=99717 written=7734 -> Hash Join (cost=57943.99..389830.25 rows=592826 width=40) (actual time=1220.715..14837.601 rows=1185466 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=112711 read=99717 written=7734 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.509..6643.865 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=72194 read=98821 written=7734 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.108..1.393 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54230.35..54230.35 rows=296413 width=40) (actual time=1218.874..1218.874 rows=296537 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21450kB Buffers: shared hit=40517 read=896 -> Bitmap Heap Scan on part (cost=5729.85..54230.35 rows=296413 width=40) (actual time=177.933..1008.091 rows=296537 loops=1) Recheck Cond: (p_size = ANY ('{19,3,25,21,18,24,40,34}'::integer[])) Filter: ((p_brand <> 'Brand#13'::bpchar) AND ((p_type)::text !~~ 'SMALL BURNISHED%'::text)) Rows Removed by Filter: 23148 Buffers: shared hit=40517 read=896 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5655.75 rows=319140 width=0) (actual time=155.312..155.312 rows=319685 loops=1) Index Cond: (p_size = ANY ('{19,3,25,21,18,24,40,34}'::integer[])) Buffers: shared hit=11 read=888 Total runtime: 47949.680 ms (32 rows) COMMIT; COMMIT