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#24' and p_type not like 'ECONOMY PLATED%' and p_size in (38, 8, 2, 40, 35, 22, 7, 14) 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=456240.47..456309.80 rows=27733 width=40) (actual time=55917.659..55919.655 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=150409 read=62035 written=7 -> GroupAggregate (cost=446521.24..454193.87 rows=27733 width=40) (actual time=54533.563..55516.646 rows=27840 loops=1) Buffers: shared hit=150393 read=62035 written=7 -> Sort (cost=446521.24..448000.30 rows=591624 width=40) (actual time=54533.444..54845.556 rows=1188226 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141983kB Buffers: shared hit=150393 read=62035 written=7 -> Hash Join (cost=57927.05..389801.29 rows=591624 width=40) (actual time=3789.460..22198.374 rows=1188226 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=150393 read=62035 written=7 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.743..9981.570 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=145137 read=25878 written=7 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.096..1.638 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54220.92..54220.92 rows=295812 width=40) (actual time=3787.459..3787.459 rows=297224 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21515kB Buffers: shared hit=5256 read=36157 -> Bitmap Heap Scan on part (cost=5727.60..54220.92 rows=295812 width=40) (actual time=265.122..3516.255 rows=297224 loops=1) Recheck Cond: (p_size = ANY ('{38,8,2,40,35,22,7,14}'::integer[])) Filter: ((p_brand <> 'Brand#24'::bpchar) AND ((p_type)::text !~~ 'ECONOMY PLATED%'::text)) Rows Removed by Filter: 22846 Buffers: shared hit=5256 read=36157 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5653.65 rows=318853 width=0) (actual time=250.349..250.349 rows=320070 loops=1) Index Cond: (p_size = ANY ('{38,8,2,40,35,22,7,14}'::integer[])) Buffers: shared hit=9 read=890 Total runtime: 55952.154 ms (32 rows) COMMIT; COMMIT