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 ANODIZED%' and p_size in (45, 41, 26, 5, 40, 33, 32, 18) 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=416730.49..416800.19 rows=27879 width=40) (actual time=16540.477..16544.626 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=127767 read=84666 written=635 -> GroupAggregate (cost=406958.90..414672.06 rows=27879 width=40) (actual time=15609.320..16483.204 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=127753 read=84666 written=635 -> Sort (cost=406958.90..408445.77 rows=594750 width=40) (actual time=15609.216..15857.140 rows=1183169 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141588kB Buffers: shared hit=127753 read=84666 written=635 -> Hash Join (cost=58011.15..349916.65 rows=594750 width=40) (actual time=1404.874..7263.853 rows=1183169 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=127753 read=84666 written=635 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.609..3866.898 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=127741 read=43273 written=605 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.057..0.524 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54277.74..54277.74 rows=297375 width=40) (actual time=1399.929..1399.929 rows=295981 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25521kB Buffers: shared hit=12 read=41393 written=30 -> Bitmap Heap Scan on part (cost=5741.91..54277.74 rows=297375 width=40) (actual time=133.498..1200.057 rows=295981 loops=1) Recheck Cond: (p_size = ANY ('{45,41,26,5,40,33,32,18}'::integer[])) Filter: ((p_brand <> 'Brand#45'::bpchar) AND ((p_type)::text !~~ 'PROMO ANODIZED%'::text)) Rows Removed by Filter: 23140 Heap Blocks: exact=40510 Buffers: shared hit=12 read=41393 written=30 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5667.57 rows=320553 width=0) (actual time=117.047..117.047 rows=319121 loops=1) Index Cond: (p_size = ANY ('{45,41,26,5,40,33,32,18}'::integer[])) Buffers: shared hit=10 read=885 Planning time: 5.011 ms Execution time: 16562.983 ms (35 rows) COMMIT; COMMIT