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#44' and p_type not like 'PROMO POLISHED%' and p_size in (6, 36, 43, 22, 44, 37, 20, 48) 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=456535.08..456604.93 rows=27942 width=40) (actual time=44920.376..44922.241 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=158895 read=53552 written=231 -> GroupAggregate (cost=446782.37..454471.54 rows=27942 width=40) (actual time=43681.002..44555.733 rows=27840 loops=1) Buffers: shared hit=158879 read=53552 written=231 -> Sort (cost=446782.37..448264.32 rows=592780 width=40) (actual time=43680.878..43945.040 rows=1186128 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141819kB Buffers: shared hit=158879 read=53552 written=231 -> Hash Join (cost=58057.45..389943.25 rows=592780 width=40) (actual time=999.670..12157.016 rows=1186128 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=158879 read=53552 written=231 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.194..4556.765 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=140609 read=30406 written=231 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.123..1.107 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54323.37..54323.37 rows=298048 width=40) (actual time=998.201..998.201 rows=296703 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21478kB Buffers: shared hit=18270 read=23146 -> Bitmap Heap Scan on part (cost=5773.20..54323.37 rows=298048 width=40) (actual time=110.630..823.687 rows=296703 loops=1) Recheck Cond: (p_size = ANY ('{6,36,43,22,44,37,20,48}'::integer[])) Filter: ((p_brand <> 'Brand#44'::bpchar) AND ((p_type)::text !~~ 'PROMO POLISHED%'::text)) Rows Removed by Filter: 23479 Buffers: shared hit=18270 read=23146 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5698.69 rows=321127 width=0) (actual time=97.376..97.376 rows=320182 loops=1) Index Cond: (p_size = ANY ('{6,36,43,22,44,37,20,48}'::integer[])) Buffers: shared hit=11 read=889 Total runtime: 44943.433 ms (32 rows) COMMIT; COMMIT