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 'STANDARD BRUSHED%' and p_size in (21, 28, 4, 31, 19, 46, 40, 26) 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=416373.11..416442.54 rows=27773 width=40) (actual time=11995.905..12000.035 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=75251 read=137190 -> GroupAggregate (cost=406639.56..414323.27 rows=27773 width=40) (actual time=11003.236..11938.910 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=75237 read=137190 -> Sort (cost=406639.56..408120.76 rows=592478 width=40) (actual time=11003.142..11298.594 rows=1185887 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141800kB Buffers: shared hit=75237 read=137190 -> Hash Join (cost=57948.80..349831.58 rows=592478 width=40) (actual time=954.932..6619.959 rows=1185887 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=75237 read=137190 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.460..3854.832 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=66027 read=104987 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.043..0.417 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54229.59..54229.59 rows=296239 width=40) (actual time=950.720..950.720 rows=296636 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25554kB Buffers: shared hit=9210 read=32203 -> Bitmap Heap Scan on part (cost=5730.59..54229.59 rows=296239 width=40) (actual time=82.748..815.347 rows=296636 loops=1) Recheck Cond: (p_size = ANY ('{21,28,4,31,19,46,40,26}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'STANDARD BRUSHED%'::text)) Rows Removed by Filter: 22821 Heap Blocks: exact=40516 Buffers: shared hit=9210 read=32203 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5656.53 rows=319080 width=0) (actual time=72.273..72.273 rows=319457 loops=1) Index Cond: (p_size = ANY ('{21,28,4,31,19,46,40,26}'::integer[])) Buffers: shared hit=118 read=779 Planning time: 4.171 ms Execution time: 12022.728 ms (35 rows) COMMIT; COMMIT