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 'MEDIUM BURNISHED%' and p_size in (15, 4, 18, 38, 22, 50, 43, 25) 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=416526.28..416595.82 rows=27816 width=40) (actual time=9816.004..9819.905 rows=27839 loops=1) Sort Key: (count(DISTINCT partsupp.ps_suppkey)), part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 2967kB Buffers: shared hit=168789 read=43652 written=22 -> GroupAggregate (cost=406777.37..414472.95 rows=27816 width=40) (actual time=9019.845..9759.621 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=168775 read=43652 written=22 -> Sort (cost=406777.37..408260.85 rows=593394 width=40) (actual time=9019.771..9180.091 rows=1185314 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141755kB Buffers: shared hit=168775 read=43652 written=22 -> Hash Join (cost=57983.01..349874.95 rows=593394 width=40) (actual time=1118.030..6094.664 rows=1185314 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=168775 read=43652 written=22 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.537..3439.792 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=168765 read=2249 written=22 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.050..0.479 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54258.07..54258.07 rows=296697 width=40) (actual time=1114.261..1114.261 rows=296494 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25541kB Buffers: shared hit=10 read=41403 -> Bitmap Heap Scan on part (cost=5737.24..54258.07 rows=296697 width=40) (actual time=95.014..986.179 rows=296494 loops=1) Recheck Cond: (p_size = ANY ('{15,4,18,38,22,50,43,25}'::integer[])) Filter: ((p_brand <> 'Brand#35'::bpchar) AND ((p_type)::text !~~ 'MEDIUM BURNISHED%'::text)) Rows Removed by Filter: 22767 Heap Blocks: exact=40517 Buffers: shared hit=10 read=41403 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5663.07 rows=319953 width=0) (actual time=84.197..84.197 rows=319261 loops=1) Index Cond: (p_size = ANY ('{15,4,18,38,22,50,43,25}'::integer[])) Buffers: shared hit=7 read=889 Planning time: 4.532 ms Execution time: 9834.249 ms (35 rows) COMMIT; COMMIT