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#55' and p_type not like 'PROMO BURNISHED%' and p_size in (7, 9, 14, 1, 22, 6, 42, 15) 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=416924.30..416994.13 rows=27933 width=40) (actual time=10845.000..10852.574 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=21718 read=190723 written=490 -> GroupAggregate (cost=407133.53..414861.49 rows=27933 width=40) (actual time=9889.967..10788.404 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=21704 read=190723 written=490 -> Sort (cost=407133.53..408623.26 rows=595890 width=40) (actual time=9889.892..10171.287 rows=1184619 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141701kB Buffers: shared hit=21704 read=190723 written=490 -> Hash Join (cost=58056.82..349973.72 rows=595890 width=40) (actual time=954.805..6490.289 rows=1184619 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=21704 read=190723 written=490 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.352..4011.165 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=16261 read=154753 written=409 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.037..0.306 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54316.28..54316.28 rows=297945 width=40) (actual time=951.256..951.256 rows=296321 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25530kB Buffers: shared hit=5443 read=35970 written=81 -> Bitmap Heap Scan on part (cost=5772.45..54316.28 rows=297945 width=40) (actual time=81.908..823.545 rows=296321 loops=1) Recheck Cond: (p_size = ANY ('{7,9,14,1,22,6,42,15}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'PROMO BURNISHED%'::text)) Rows Removed by Filter: 23205 Heap Blocks: exact=40515 Buffers: shared hit=5443 read=35970 written=81 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5697.97 rows=320873 width=0) (actual time=71.699..71.699 rows=319526 loops=1) Index Cond: (p_size = ANY ('{7,9,14,1,22,6,42,15}'::integer[])) Buffers: shared hit=9 read=889 written=4 Planning time: 4.197 ms Execution time: 10869.843 ms (35 rows) COMMIT; COMMIT