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#22' and p_type not like 'LARGE ANODIZED%' and p_size in (33, 6, 3, 20, 35, 29, 46, 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=416678.45..416748.35 rows=27961 width=40) (actual time=9340.847..9342.535 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=81 read=212360 -> GroupAggregate (cost=406912.32..414613.37 rows=27961 width=40) (actual time=8464.885..9291.962 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=67 read=212360 -> Sort (cost=406912.32..408396.61 rows=593715 width=40) (actual time=8464.752..8715.477 rows=1188370 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141994kB Buffers: shared hit=67 read=212360 -> Hash Join (cost=58081.65..349976.80 rows=593715 width=40) (actual time=973.954..5836.066 rows=1188370 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=67 read=212360 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.816..3523.705 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=57 read=170957 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.035..0.757 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54337.39..54337.39 rows=298243 width=40) (actual time=970.719..970.719 rows=297270 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25615kB Buffers: shared hit=10 read=41403 -> Bitmap Heap Scan on part (cost=5777.39..54337.39 rows=298243 width=40) (actual time=72.591..851.917 rows=297270 loops=1) Recheck Cond: (p_size = ANY ('{33,6,3,20,35,29,46,19}'::integer[])) Filter: ((p_brand <> 'Brand#22'::bpchar) AND ((p_type)::text !~~ 'LARGE ANODIZED%'::text)) Rows Removed by Filter: 23048 Heap Blocks: exact=40514 Buffers: shared hit=10 read=41403 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5702.83 rows=321520 width=0) (actual time=62.902..62.902 rows=320318 loops=1) Index Cond: (p_size = ANY ('{33,6,3,20,35,29,46,19}'::integer[])) Buffers: shared hit=8 read=891 Planning time: 6.326 ms Execution time: 9353.041 ms (35 rows) COMMIT; COMMIT