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#45' and p_type not like 'ECONOMY PLATED%' and p_size in (47, 45, 11, 18, 32, 27, 16, 46) 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=416099.34..416168.56 rows=27687 width=40) (actual time=10683.918..10687.738 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=166941 read=45499 written=2615 -> GroupAggregate (cost=406396.60..414056.47 rows=27687 width=40) (actual time=9800.043..10628.443 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=166927 read=45499 written=2615 -> Sort (cost=406396.60..407873.20 rows=590640 width=40) (actual time=9799.934..10028.053 rows=1184672 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141705kB Buffers: shared hit=166927 read=45499 written=2615 -> Hash Join (cost=57913.68..349778.08 rows=590640 width=40) (actual time=1183.541..6355.990 rows=1184672 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=166927 read=45499 written=2615 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.555..3622.808 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=146019 read=24995 written=1622 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.051..0.509 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54205.96..54205.96 rows=295320 width=40) (actual time=1179.881..1179.881 rows=296340 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25548kB Buffers: shared hit=20908 read=20504 written=993 -> Bitmap Heap Scan on part (cost=5724.96..54205.96 rows=295320 width=40) (actual time=85.840..1040.623 rows=296340 loops=1) Recheck Cond: (p_size = ANY ('{47,45,11,18,32,27,16,46}'::integer[])) Filter: ((p_brand <> 'Brand#45'::bpchar) AND ((p_type)::text !~~ 'ECONOMY PLATED%'::text)) Rows Removed by Filter: 23154 Heap Blocks: exact=40516 Buffers: shared hit=20908 read=20504 written=993 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5651.13 rows=318360 width=0) (actual time=75.410..75.410 rows=319494 loops=1) Index Cond: (p_size = ANY ('{47,45,11,18,32,27,16,46}'::integer[])) Buffers: shared hit=125 read=771 written=26 Planning time: 4.767 ms Execution time: 10710.780 ms (35 rows) COMMIT; COMMIT