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#55' and p_type not like 'STANDARD ANODIZED%' and p_size in (11, 16, 49, 42, 29, 22, 15, 14) 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=416536.50..416606.06 rows=27822 width=40) (actual time=12173.945..12182.155 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=59968 read=152477 written=451 -> GroupAggregate (cost=406785.37..414482.69 rows=27822 width=40) (actual time=11180.959..12113.033 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=59954 read=152477 written=451 -> Sort (cost=406785.37..408269.19 rows=593528 width=40) (actual time=11180.868..11483.785 rows=1186100 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141817kB Buffers: shared hit=59954 read=152477 written=451 -> Hash Join (cost=57975.85..349869.13 rows=593528 width=40) (actual time=1125.115..7619.894 rows=1186100 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=59954 read=152477 written=451 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.485..4397.862 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=49076 read=121938 written=170 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.059..0.432 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54250.07..54250.07 rows=296764 width=40) (actual time=1119.173..1119.173 rows=296698 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25550kB Buffers: shared hit=10878 read=30539 written=281 -> Bitmap Heap Scan on part (cost=5735.40..54250.07 rows=296764 width=40) (actual time=139.113..951.114 rows=296698 loops=1) Recheck Cond: (p_size = ANY ('{11,16,49,42,29,22,15,14}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'STANDARD ANODIZED%'::text)) Rows Removed by Filter: 23217 Heap Blocks: exact=40517 Buffers: shared hit=10878 read=30539 written=281 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5661.21 rows=319707 width=0) (actual time=121.705..121.705 rows=319915 loops=1) Index Cond: (p_size = ANY ('{11,16,49,42,29,22,15,14}'::integer[])) Buffers: shared hit=10 read=890 written=4 Planning time: 5.313 ms Execution time: 12205.363 ms (35 rows) COMMIT; COMMIT