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#45' and p_type not like 'PROMO BRUSHED%' and p_size in (5, 4, 29, 41, 30, 12, 14, 1) 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=416918.84..416988.65 rows=27926 width=40) (actual time=13993.638..13997.980 rows=27837 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=43733 read=168712 written=5325 -> GroupAggregate (cost=407130.59..414856.60 rows=27926 width=40) (actual time=12954.963..13935.651 rows=27837 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=43719 read=168712 written=5325 -> Sort (cost=407130.59..408619.94 rows=595740 width=40) (actual time=12954.855..13269.790 rows=1187252 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141907kB Buffers: shared hit=43719 read=168712 written=5325 -> Hash Join (cost=58070.84..349986.24 rows=595740 width=40) (actual time=1042.813..7498.389 rows=1187252 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=43719 read=168712 written=5325 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.632..4595.111 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=7427 read=163587 written=5318 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.058..0.563 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54331.24..54331.24 rows=297870 width=40) (actual time=1038.967..1038.967 rows=296993 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25610kB Buffers: shared hit=36292 read=5125 written=7 -> Bitmap Heap Scan on part (cost=5775.91..54331.24 rows=297870 width=40) (actual time=129.631..872.913 rows=296993 loops=1) Recheck Cond: (p_size = ANY ('{5,4,29,41,30,12,14,1}'::integer[])) Filter: ((p_brand <> 'Brand#45'::bpchar) AND ((p_type)::text !~~ 'PROMO BRUSHED%'::text)) Rows Removed by Filter: 22931 Heap Blocks: exact=40520 Buffers: shared hit=36292 read=5125 written=7 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5701.45 rows=321333 width=0) (actual time=114.420..114.420 rows=319924 loops=1) Index Cond: (p_size = ANY ('{5,4,29,41,30,12,14,1}'::integer[])) Buffers: shared hit=12 read=885 Planning time: 5.594 ms Execution time: 14018.386 ms (35 rows) COMMIT; COMMIT