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#41' and p_type not like 'PROMO BURNISHED%' and p_size in (15, 30, 46, 23, 18, 4, 35, 1) 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=416361.59..416431.02 rows=27770 width=40) (actual time=12730.016..12733.932 rows=27838 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=18277 read=194163 written=211 -> GroupAggregate (cost=406629.22..414311.99 rows=27770 width=40) (actual time=11641.047..12673.507 rows=27838 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=18263 read=194163 written=211 -> Sort (cost=406629.22..408110.23 rows=592406 width=40) (actual time=11640.946..11987.125 rows=1186727 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141866kB Buffers: shared hit=18263 read=194163 written=211 -> Hash Join (cost=57946.60..349828.66 rows=592406 width=40) (actual time=1084.687..7711.905 rows=1186727 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=18263 read=194163 written=211 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.554..4756.510 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=15677 read=155337 written=178 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.051..0.499 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54227.83..54227.83 rows=296203 width=40) (actual time=1080.433..1080.433 rows=296849 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25566kB Buffers: shared hit=2586 read=38826 written=33 -> Bitmap Heap Scan on part (cost=5730.16..54227.83 rows=296203 width=40) (actual time=88.027..942.068 rows=296849 loops=1) Recheck Cond: (p_size = ANY ('{15,30,46,23,18,4,35,1}'::integer[])) Filter: ((p_brand <> 'Brand#41'::bpchar) AND ((p_type)::text !~~ 'PROMO BURNISHED%'::text)) Rows Removed by Filter: 23000 Heap Blocks: exact=40517 Buffers: shared hit=2586 read=38826 written=33 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5656.11 rows=319027 width=0) (actual time=77.549..77.549 rows=319849 loops=1) Index Cond: (p_size = ANY ('{15,30,46,23,18,4,35,1}'::integer[])) Buffers: shared hit=7 read=888 Planning time: 4.009 ms Execution time: 12755.371 ms (35 rows) COMMIT; COMMIT