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 'STANDARD ANODIZED%' and p_size in (22, 5, 7, 27, 36, 16, 23, 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=412335.41..412404.81 rows=27760 width=40) (actual time=11215.143..11218.069 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=9726 read=201833 written=3561 -> GroupAggregate (cost=402681.03..410286.62 rows=27760 width=40) (actual time=10421.986..11155.967 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=9712 read=201833 written=3561 -> Sort (cost=402681.03..404146.63 rows=586239 width=40) (actual time=10421.922..10566.137 rows=1188359 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141993kB Buffers: shared hit=9712 read=201833 written=3561 -> Hash Join (cost=54695.64..346516.03 rows=586239 width=40) (actual time=1299.814..6866.363 rows=1188359 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=9712 read=201833 written=3561 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.510..4045.756 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=581 read=170433 written=763 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.035..0.469 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=50978.13..50978.13 rows=296102 width=40) (actual time=1297.369..1297.369 rows=297249 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25590kB Buffers: shared hit=9131 read=31400 written=2798 -> Bitmap Heap Scan on part (cost=2479.13..50978.13 rows=296102 width=40) (actual time=34.729..1174.410 rows=297249 loops=1) Recheck Cond: (p_size = ANY ('{22,5,7,27,36,16,23,8}'::integer[])) Rows Removed by Index Recheck: 1679638 Filter: ((p_brand <> 'Brand#45'::bpchar) AND ((p_type)::text !~~ 'STANDARD ANODIZED%'::text)) Rows Removed by Filter: 23113 Heap Blocks: lossy=40522 Buffers: shared hit=9131 read=31400 written=2798 -> Bitmap Index Scan on part_p_size_brin_idx (cost=0.00..2405.11 rows=319080 width=0) (actual time=34.676..34.676 rows=3246080 loops=1) Index Cond: (p_size = ANY ('{22,5,7,27,36,16,23,8}'::integer[])) Buffers: shared hit=7 read=2 Planning time: 3.765 ms Execution time: 11227.794 ms (36 rows) COMMIT; COMMIT