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#24' and p_type not like 'STANDARD ANODIZED%' and p_size in (18, 44, 5, 11, 24, 22, 21, 49) 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=416905.93..416975.74 rows=27926 width=40) (actual time=9671.982..9675.029 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=152224 read=60214 written=2 -> GroupAggregate (cost=407117.73..414843.69 rows=27926 width=40) (actual time=8874.926..9616.722 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=152210 read=60214 written=2 -> Sort (cost=407117.73..408607.07 rows=595736 width=40) (actual time=8874.841..9043.196 rows=1186703 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141864kB Buffers: shared hit=152210 read=60214 written=2 -> Hash Join (cost=58058.44..349973.80 rows=595736 width=40) (actual time=945.252..6034.533 rows=1186703 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=152210 read=60214 written=2 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.457..3585.503 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=139091 read=31923 written=2 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.049..0.408 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54318.86..54318.86 rows=297868 width=40) (actual time=942.336..942.336 rows=296851 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25561kB Buffers: shared hit=13119 read=28291 -> Bitmap Heap Scan on part (cost=5773.03..54318.86 rows=297868 width=40) (actual time=86.719..816.957 rows=296851 loops=1) Recheck Cond: (p_size = ANY ('{18,44,5,11,24,22,21,49}'::integer[])) Filter: ((p_brand <> 'Brand#24'::bpchar) AND ((p_type)::text !~~ 'STANDARD ANODIZED%'::text)) Rows Removed by Filter: 22914 Heap Blocks: exact=40511 Buffers: shared hit=13119 read=28291 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5698.57 rows=320953 width=0) (actual time=76.017..76.017 rows=319765 loops=1) Index Cond: (p_size = ANY ('{18,44,5,11,24,22,21,49}'::integer[])) Buffers: shared hit=9 read=890 Planning time: 4.833 ms Execution time: 9693.086 ms (35 rows) COMMIT; COMMIT