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#12' and p_type not like 'LARGE POLISHED%' and p_size in (1, 30, 13, 33, 14, 20, 50, 26) 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=456460.21..456530.00 rows=27917 width=40) (actual time=53315.586..53317.664 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=183224 read=29218 -> GroupAggregate (cost=446712.52..454398.69 rows=27917 width=40) (actual time=51890.597..52909.096 rows=27839 loops=1) Buffers: shared hit=183208 read=29218 -> Sort (cost=446712.52..448193.92 rows=592560 width=40) (actual time=51890.496..52212.783 rows=1184704 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141708kB Buffers: shared hit=183208 read=29218 -> Hash Join (cost=58012.49..389896.09 rows=592560 width=40) (actual time=3175.967..19537.235 rows=1184704 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=183208 read=29218 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=3.513..8550.709 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=165179 read=5836 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=1.115..3.419 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54281.84..54281.84 rows=297774 width=40) (actual time=3172.129..3172.129 rows=296342 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21450kB Buffers: shared hit=18029 read=23382 -> Bitmap Heap Scan on part (cost=5742.01..54281.84 rows=297774 width=40) (actual time=213.983..2899.972 rows=296342 loops=1) Recheck Cond: (p_size = ANY ('{1,30,13,33,14,20,50,26}'::integer[])) Filter: ((p_brand <> 'Brand#12'::bpchar) AND ((p_type)::text !~~ 'LARGE POLISHED%'::text)) Rows Removed by Filter: 23094 Buffers: shared hit=18029 read=23382 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5667.57 rows=320713 width=0) (actual time=198.485..198.485 rows=319436 loops=1) Index Cond: (p_size = ANY ('{1,30,13,33,14,20,50,26}'::integer[])) Buffers: shared hit=122 read=775 Total runtime: 53342.457 ms (32 rows) COMMIT; COMMIT