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#42' and p_type not like 'STANDARD ANODIZED%' and p_size in (5, 2, 46, 14, 11, 13, 29, 30) 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=456027.68..456097.14 rows=27785 width=40) (actual time=48935.607..48939.067 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=85988 read=126458 written=887 -> GroupAggregate (cost=446326.92..453976.87 rows=27785 width=40) (actual time=47604.048..48553.711 rows=27840 loops=1) Buffers: shared hit=85972 read=126458 written=887 -> Sort (cost=446326.92..447801.34 rows=589768 width=40) (actual time=47603.930..47908.637 rows=1185568 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141775kB Buffers: shared hit=85972 read=126458 written=887 -> Hash Join (cost=57942.60..389798.28 rows=589768 width=40) (actual time=1601.293..15720.806 rows=1185568 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=85972 read=126458 written=887 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.349..6846.847 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=78095 read=92920 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.089..1.243 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54229.48..54229.48 rows=296371 width=40) (actual time=1599.584..1599.584 rows=296563 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21443kB Buffers: shared hit=7877 read=33538 written=887 -> Bitmap Heap Scan on part (cost=5729.66..54229.48 rows=296371 width=40) (actual time=95.123..1389.766 rows=296563 loops=1) Recheck Cond: (p_size = ANY ('{5,2,46,14,11,13,29,30}'::integer[])) Filter: ((p_brand <> 'Brand#42'::bpchar) AND ((p_type)::text !~~ 'STANDARD ANODIZED%'::text)) Rows Removed by Filter: 22746 Buffers: shared hit=7877 read=33538 written=887 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5655.57 rows=319113 width=0) (actual time=84.170..84.170 rows=319309 loops=1) Index Cond: (p_size = ANY ('{5,2,46,14,11,13,29,30}'::integer[])) Buffers: shared hit=10 read=886 Total runtime: 48960.466 ms (32 rows) COMMIT; COMMIT