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#54' and p_type not like 'ECONOMY PLATED%' and p_size in (33, 17, 47, 8, 1, 13, 40, 4) 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=457208.51..457278.76 rows=28099 width=40) (actual time=37676.589..37678.314 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=82 read=212362 -> GroupAggregate (cost=447384.29..455132.24 rows=28099 width=40) (actual time=36527.478..37344.650 rows=27839 loops=1) Buffers: shared hit=66 read=212362 -> Sort (cost=447384.29..448877.68 rows=597357 width=40) (actual time=36527.223..36777.664 rows=1187668 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141939kB Buffers: shared hit=66 read=212362 -> Hash Join (cost=58141.59..390073.16 rows=597357 width=40) (actual time=849.024..9576.470 rows=1187668 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=66 read=212362 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.316..3544.760 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=57 read=170958 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.120..1.211 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54386.64..54386.64 rows=299718 width=40) (actual time=847.398..847.398 rows=297079 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21504kB Buffers: shared hit=9 read=41404 -> Bitmap Heap Scan on part (cost=5788.14..54386.64 rows=299718 width=40) (actual time=84.054..734.117 rows=297079 loops=1) Recheck Cond: (p_size = ANY ('{33,17,47,8,1,13,40,4}'::integer[])) Filter: ((p_brand <> 'Brand#54'::bpchar) AND ((p_type)::text !~~ 'ECONOMY PLATED%'::text)) Rows Removed by Filter: 22858 Buffers: shared hit=9 read=41404 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5713.21 rows=323060 width=0) (actual time=74.289..74.289 rows=319937 loops=1) Index Cond: (p_size = ANY ('{33,17,47,8,1,13,40,4}'::integer[])) Buffers: shared hit=7 read=891 Total runtime: 37691.117 ms (32 rows) COMMIT; COMMIT