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#11' and p_type not like 'STANDARD BURNISHED%' and p_size in (31, 21, 5, 28, 50, 47, 23, 19) 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=416663.90..416733.56 rows=27863 width=40) (actual time=10847.913..10855.961 rows=27840 loops=1) Sort Key: (count(DISTINCT partsupp.ps_suppkey)), part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 2944kB Buffers: shared hit=121094 read=91346 written=29 -> GroupAggregate (cost=406898.19..414606.77 rows=27863 width=40) (actual time=9648.556..10751.594 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=121080 read=91346 written=29 -> Sort (cost=406898.19..408384.18 rows=594396 width=40) (actual time=9648.492..9931.922 rows=1186325 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141834kB Buffers: shared hit=121080 read=91346 written=29 -> Hash Join (cost=57990.48..349892.44 rows=594396 width=40) (actual time=1044.173..6358.466 rows=1186325 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=121080 read=91346 written=29 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.445..3717.199 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=117099 read=53915 written=2 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.046..0.401 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54259.28..54259.28 rows=297198 width=40) (actual time=1040.379..1040.379 rows=296755 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25539kB Buffers: shared hit=3981 read=37431 written=27 -> Bitmap Heap Scan on part (cost=5737.61..54259.28 rows=297198 width=40) (actual time=92.085..905.181 rows=296755 loops=1) Recheck Cond: (p_size = ANY ('{31,21,5,28,50,47,23,19}'::integer[])) Filter: ((p_brand <> 'Brand#11'::bpchar) AND ((p_type)::text !~~ 'STANDARD BURNISHED%'::text)) Rows Removed by Filter: 22926 Heap Blocks: exact=40513 Buffers: shared hit=3981 read=37431 written=27 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5663.31 rows=319987 width=0) (actual time=80.870..80.870 rows=319681 loops=1) Index Cond: (p_size = ANY ('{31,21,5,28,50,47,23,19}'::integer[])) Buffers: shared hit=7 read=892 Planning time: 4.355 ms Execution time: 10889.588 ms (35 rows) COMMIT; COMMIT