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#42' and p_type not like 'PROMO ANODIZED%' and p_size in (45, 38, 43, 25, 20, 34, 47, 18) 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=456113.34..456182.86 rows=27810 width=40) (actual time=54585.730..54588.959 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=40985 read=171463 written=15 -> GroupAggregate (cost=446403.73..454060.50 rows=27810 width=40) (actual time=52877.896..54117.000 rows=27839 loops=1) Buffers: shared hit=40969 read=171463 written=15 -> Sort (cost=446403.73..447879.47 rows=590293 width=40) (actual time=52877.781..53195.289 rows=1186064 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141814kB Buffers: shared hit=40969 read=171463 written=15 -> Hash Join (cost=57960.06..389820.99 rows=590293 width=40) (actual time=2016.277..20576.809 rows=1186064 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=40969 read=171463 written=15 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.370..10897.481 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=40959 read=130056 written=15 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.097..1.274 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54243.64..54243.64 rows=296635 width=40) (actual time=2014.575..2014.575 rows=296684 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21476kB Buffers: shared hit=10 read=41407 -> Bitmap Heap Scan on part (cost=5732.97..54243.64 rows=296635 width=40) (actual time=134.368..1754.508 rows=296684 loops=1) Recheck Cond: (p_size = ANY ('{45,38,43,25,20,34,47,18}'::integer[])) Filter: ((p_brand <> 'Brand#42'::bpchar) AND ((p_type)::text !~~ 'PROMO ANODIZED%'::text)) Rows Removed by Filter: 22933 Buffers: shared hit=10 read=41407 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5658.81 rows=319547 width=0) (actual time=119.703..119.703 rows=319617 loops=1) Index Cond: (p_size = ANY ('{45,38,43,25,20,34,47,18}'::integer[])) Buffers: shared hit=8 read=890 Total runtime: 54615.278 ms (32 rows) COMMIT; COMMIT