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#25' and p_type not like 'SMALL ANODIZED%' and p_size in (28, 7, 8, 47, 15, 46, 4, 18) 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=416154.51..416223.76 rows=27703 width=40) (actual time=10287.505..10291.314 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=37054 read=175386 written=35 -> GroupAggregate (cost=406445.86..414110.34 rows=27703 width=40) (actual time=9504.867..10230.921 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=37040 read=175386 written=35 -> Sort (cost=406445.86..407923.35 rows=590996 width=40) (actual time=9504.797..9660.614 rows=1186015 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141810kB Buffers: shared hit=37040 read=175386 written=35 -> Hash Join (cost=57922.69..349790.65 rows=590996 width=40) (actual time=773.482..6637.877 rows=1186015 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=37040 read=175386 written=35 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.470..4321.568 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=6587 read=164427 written=35 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.054..0.420 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54212.74..54212.74 rows=295498 width=40) (actual time=770.437..770.437 rows=296671 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25571kB Buffers: shared hit=30453 read=10959 -> Bitmap Heap Scan on part (cost=5726.56..54212.74 rows=295498 width=40) (actual time=87.619..651.886 rows=296671 loops=1) Recheck Cond: (p_size = ANY ('{28,7,8,47,15,46,4,18}'::integer[])) Filter: ((p_brand <> 'Brand#25'::bpchar) AND ((p_type)::text !~~ 'SMALL ANODIZED%'::text)) Rows Removed by Filter: 22990 Heap Blocks: exact=40516 Buffers: shared hit=30453 read=10959 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5652.69 rows=318567 width=0) (actual time=76.795..76.795 rows=319661 loops=1) Index Cond: (p_size = ANY ('{28,7,8,47,15,46,4,18}'::integer[])) Buffers: shared hit=11 read=885 Planning time: 4.566 ms Execution time: 10303.393 ms (35 rows) COMMIT; COMMIT