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#34' and p_type not like 'LARGE BRUSHED%' and p_size in (15, 23, 20, 30, 28, 29, 42, 45) 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=416549.56..416619.12 rows=27825 width=40) (actual time=9185.230..9186.973 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=28 read=212416 -> GroupAggregate (cost=406797.25..414495.50 rows=27825 width=40) (actual time=8505.789..9136.625 rows=27840 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=14 read=212416 -> Sort (cost=406797.25..408281.25 rows=593600 width=40) (actual time=8505.688..8636.220 rows=1186783 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141870kB Buffers: shared hit=14 read=212416 -> Hash Join (cost=57979.59..349873.59 rows=593600 width=40) (actual time=968.886..6156.907 rows=1186783 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=14 read=212416 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=1.335..3868.795 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=2 read=171012 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..1.257 rows=56 loops=1) Buffers: shared read=56 -> Hash (cost=54253.36..54253.36 rows=296800 width=40) (actual time=965.089..965.089 rows=296867 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25601kB Buffers: shared hit=12 read=41404 -> Bitmap Heap Scan on part (cost=5736.19..54253.36 rows=296800 width=40) (actual time=70.387..841.869 rows=296867 loops=1) Recheck Cond: (p_size = ANY ('{15,23,20,30,28,29,42,45}'::integer[])) Filter: ((p_brand <> 'Brand#34'::bpchar) AND ((p_type)::text !~~ 'LARGE BRUSHED%'::text)) Rows Removed by Filter: 23133 Heap Blocks: exact=40518 Buffers: shared hit=12 read=41404 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5661.99 rows=319807 width=0) (actual time=60.686..60.686 rows=320000 loops=1) Index Cond: (p_size = ANY ('{15,23,20,30,28,29,42,45}'::integer[])) Buffers: shared hit=10 read=888 Planning time: 7.179 ms Execution time: 9196.826 ms (35 rows) COMMIT; COMMIT