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#14' and p_type not like 'STANDARD BURNISHED%' and p_size in (3, 42, 4, 33, 14, 16, 47, 32) 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=456943.55..457013.60 rows=28019 width=40) (actual time=48822.043..48826.737 rows=27839 loops=1) Sort Key: (count(DISTINCT partsupp.ps_suppkey)), part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 2943kB Buffers: shared hit=29728 read=182719 written=12 -> GroupAggregate (cost=447147.99..454873.77 rows=28019 width=40) (actual time=47560.257..48480.153 rows=27839 loops=1) Buffers: shared hit=29712 read=182719 written=12 -> Sort (cost=447147.99..448637.11 rows=595647 width=40) (actual time=47560.153..47847.414 rows=1190018 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 142123kB Buffers: shared hit=29712 read=182719 written=12 -> Hash Join (cost=58098.77..390013.24 rows=595647 width=40) (actual time=1348.614..15521.549 rows=1190018 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=29712 read=182719 written=12 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=0.832..6566.687 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=16817 read=154198 written=12 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.076..0.770 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54354.54..54354.54 rows=298860 width=40) (actual time=1346.961..1346.961 rows=297676 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21507kB Buffers: shared hit=12895 read=28521 -> Bitmap Heap Scan on part (cost=5780.54..54354.54 rows=298860 width=40) (actual time=88.633..1130.160 rows=297676 loops=1) Recheck Cond: (p_size = ANY ('{3,42,4,33,14,16,47,32}'::integer[])) Filter: ((p_brand <> 'Brand#14'::bpchar) AND ((p_type)::text !~~ 'STANDARD BURNISHED%'::text)) Rows Removed by Filter: 23070 Buffers: shared hit=12895 read=28521 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5705.83 rows=322080 width=0) (actual time=77.597..77.597 rows=320746 loops=1) Index Cond: (p_size = ANY ('{3,42,4,33,14,16,47,32}'::integer[])) Buffers: shared hit=9 read=893 Total runtime: 48849.811 ms (32 rows) COMMIT; COMMIT