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#24' and p_type not like 'PROMO BRUSHED%' and p_size in (20, 46, 25, 30, 44, 27, 31, 8) 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=455780.00..455849.18 rows=27672 width=40) (actual time=50682.190..50685.302 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=20496 read=191942 written=18 -> GroupAggregate (cost=446108.11..453738.34 rows=27672 width=40) (actual time=49363.387..50298.947 rows=27840 loops=1) Buffers: shared hit=20480 read=191942 written=18 -> Sort (cost=446108.11..447578.81 rows=588281 width=40) (actual time=49363.252..49660.353 rows=1185553 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141774kB Buffers: shared hit=20480 read=191942 written=18 -> Hash Join (cost=57891.90..389732.71 rows=588281 width=40) (actual time=2013.162..17324.561 rows=1185553 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=20480 read=191942 written=18 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.417..7814.522 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=17950 read=153065 written=18 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.124..1.289 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54193.87..54193.87 rows=295164 width=40) (actual time=2010.946..2010.946 rows=296549 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21482kB Buffers: shared hit=2530 read=38877 -> Bitmap Heap Scan on part (cost=5721.20..54193.87 rows=295164 width=40) (actual time=147.022..1743.350 rows=296549 loops=1) Recheck Cond: (p_size = ANY ('{20,46,25,30,44,27,31,8}'::integer[])) Filter: ((p_brand <> 'Brand#24'::bpchar) AND ((p_type)::text !~~ 'PROMO BRUSHED%'::text)) Rows Removed by Filter: 22896 Buffers: shared hit=2530 read=38877 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5647.41 rows=318027 width=0) (actual time=130.109..130.109 rows=319445 loops=1) Index Cond: (p_size = ANY ('{20,46,25,30,44,27,31,8}'::integer[])) Buffers: shared hit=10 read=887 Total runtime: 50707.000 ms (32 rows) COMMIT; COMMIT