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#35' and p_type not like 'PROMO ANODIZED%' and p_size in (6, 13, 48, 22, 50, 37, 35, 3) 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=412777.80..412847.53 rows=27893 width=40) (actual time=11102.852..11105.958 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=5572 read=205987 written=30 -> GroupAggregate (cost=403076.26..410718.23 rows=27893 width=40) (actual time=10280.454..11043.630 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=5558 read=205987 written=30 -> Sort (cost=403076.26..404548.87 rows=589043 width=40) (actual time=10280.394..10447.162 rows=1189442 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 142078kB Buffers: shared hit=5558 read=205987 written=30 -> Hash Join (cost=54773.91..346622.34 rows=589043 width=40) (actual time=1289.432..6731.240 rows=1189442 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=5558 read=205987 written=30 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.570..3765.783 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=5549 read=165465 written=30 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.034..0.524 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=51038.71..51038.71 rows=297518 width=40) (actual time=1286.399..1286.399 rows=297536 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25634kB Buffers: shared hit=9 read=40522 -> Bitmap Heap Scan on part (cost=2493.39..51038.71 rows=297518 width=40) (actual time=34.925..1162.141 rows=297536 loops=1) Recheck Cond: (p_size = ANY ('{6,13,48,22,50,37,35,3}'::integer[])) Rows Removed by Index Recheck: 1679493 Filter: ((p_brand <> 'Brand#35'::bpchar) AND ((p_type)::text !~~ 'PROMO ANODIZED%'::text)) Rows Removed by Filter: 22971 Heap Blocks: lossy=40522 Buffers: shared hit=9 read=40522 -> Bitmap Index Scan on part_p_size_brin_idx (cost=0.00..2419.01 rows=320933 width=0) (actual time=34.857..34.857 rows=3246080 loops=1) Index Cond: (p_size = ANY ('{6,13,48,22,50,37,35,3}'::integer[])) Buffers: shared hit=7 read=2 Planning time: 3.940 ms Execution time: 11118.879 ms (36 rows) COMMIT; COMMIT