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#25' and p_type not like 'MEDIUM BURNISHED%' and p_size in (8, 25, 14, 22, 27, 50, 37, 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=416574.96..416644.55 rows=27834 width=40) (actual time=10890.113..10893.783 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=116996 read=95446 written=1019 -> GroupAggregate (cost=406819.59..414520.18 rows=27834 width=40) (actual time=10059.303..10833.827 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=116982 read=95446 written=1019 -> Sort (cost=406819.59..408304.04 rows=593780 width=40) (actual time=10059.226..10245.429 rows=1186133 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141819kB Buffers: shared hit=116982 read=95446 written=1019 -> Hash Join (cost=57981.57..349877.37 rows=593780 width=40) (actual time=749.261..6885.937 rows=1186133 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=116982 read=95446 written=1019 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.600..4364.190 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=76344 read=94670 written=1019 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.034..0.512 rows=56 loops=1) Buffers: shared hit=56 -> Hash (cost=54254.21..54254.21 rows=296890 width=40) (actual time=743.906..743.906 rows=296700 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25558kB Buffers: shared hit=40638 read=776 -> Bitmap Heap Scan on part (cost=5736.39..54254.21 rows=296890 width=40) (actual time=122.313..602.495 rows=296700 loops=1) Recheck Cond: (p_size = ANY ('{8,25,14,22,27,50,37,34}'::integer[])) Filter: ((p_brand <> 'Brand#25'::bpchar) AND ((p_type)::text !~~ 'MEDIUM BURNISHED%'::text)) Rows Removed by Filter: 22741 Heap Blocks: exact=40516 Buffers: shared hit=40638 read=776 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5662.17 rows=319833 width=0) (actual time=107.803..107.803 rows=319441 loops=1) Index Cond: (p_size = ANY ('{8,25,14,22,27,50,37,34}'::integer[])) Buffers: shared hit=123 read=775 Planning time: 5.347 ms Execution time: 10915.457 ms (35 rows) COMMIT; COMMIT