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#21' and p_type not like 'MEDIUM BRUSHED%' and p_size in (50, 33, 9, 44, 22, 15, 3, 13) 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=456138.91..456208.42 rows=27801 width=40) (actual time=47521.694..47523.746 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=19245 read=193195 written=301 -> GroupAggregate (cost=446427.32..454086.80 rows=27801 width=40) (actual time=46177.434..47128.747 rows=27840 loops=1) Buffers: shared hit=19229 read=193195 written=301 -> Sort (cost=446427.32..447903.61 rows=590518 width=40) (actual time=46177.308..46470.212 rows=1184775 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141713kB Buffers: shared hit=19229 read=193195 written=301 -> Hash Join (cost=57958.20..389821.38 rows=590518 width=40) (actual time=1439.039..14732.395 rows=1184775 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=19229 read=193195 written=301 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=0.963..6503.971 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=11034 read=159981 written=218 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.083..0.901 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54243.00..54243.00 rows=296538 width=40) (actual time=1437.131..1437.131 rows=296361 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21452kB Buffers: shared hit=8195 read=33214 written=83 -> Bitmap Heap Scan on part (cost=5732.82..54243.00 rows=296538 width=40) (actual time=110.475..1223.678 rows=296361 loops=1) Recheck Cond: (p_size = ANY ('{50,33,9,44,22,15,3,13}'::integer[])) Filter: ((p_brand <> 'Brand#21'::bpchar) AND ((p_type)::text !~~ 'MEDIUM BRUSHED%'::text)) Rows Removed by Filter: 22897 Buffers: shared hit=8195 read=33214 written=83 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5658.69 rows=319527 width=0) (actual time=98.674..98.674 rows=319258 loops=1) Index Cond: (p_size = ANY ('{50,33,9,44,22,15,3,13}'::integer[])) Buffers: shared hit=7 read=892 Total runtime: 47538.264 ms (32 rows) COMMIT; COMMIT