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#24' and p_type not like 'PROMO BRUSHED%' and p_size in (50, 35, 18, 30, 17, 47, 49, 10) 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=457494.18..457564.45 rows=28109 width=40) (actual time=41818.035..41820.648 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=40104 read=172339 written=16 -> GroupAggregate (cost=447640.36..455417.10 rows=28109 width=40) (actual time=40613.568..41463.408 rows=27839 loops=1) Buffers: shared hit=40088 read=172339 written=16 -> Sort (cost=447640.36..449139.49 rows=599652 width=40) (actual time=40613.458..40872.838 rows=1187500 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141926kB Buffers: shared hit=40088 read=172339 written=16 -> Hash Join (cost=58137.94..390092.46 rows=599652 width=40) (actual time=924.298..11407.321 rows=1187500 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=40088 read=172339 written=16 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.017..4583.325 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=26008 read=145007 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.060..0.955 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54381.64..54381.64 rows=299826 width=40) (actual time=922.950..922.950 rows=297041 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21517kB Buffers: shared hit=14080 read=27332 -> Bitmap Heap Scan on part (cost=5786.96..54381.64 rows=299826 width=40) (actual time=88.432..781.063 rows=297041 loops=1) Recheck Cond: (p_size = ANY ('{50,35,18,30,17,47,49,10}'::integer[])) Filter: ((p_brand <> 'Brand#24'::bpchar) AND ((p_type)::text !~~ 'PROMO BRUSHED%'::text)) Rows Removed by Filter: 23122 Buffers: shared hit=14080 read=27332 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5712.01 rows=322907 width=0) (actual time=74.097..74.097 rows=320163 loops=1) Index Cond: (p_size = ANY ('{50,35,18,30,17,47,49,10}'::integer[])) Buffers: shared hit=124 read=775 Total runtime: 41838.816 ms (32 rows) COMMIT; COMMIT