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#35' and p_type not like 'PROMO BRUSHED%' and p_size in (40, 4, 41, 10, 38, 3, 14, 5) 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=416834.65..416904.40 rows=27901 width=40) (actual time=10553.285..10562.341 rows=27838 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=5523 read=206918 written=144 -> GroupAggregate (cost=407055.20..414774.44 rows=27901 width=40) (actual time=9775.226..10494.133 rows=27838 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=5509 read=206918 written=144 -> Sort (cost=407055.20..408543.25 rows=595218 width=40) (actual time=9775.147..9938.419 rows=1188904 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 142036kB Buffers: shared hit=5509 read=206918 written=144 -> Hash Join (cost=58054.51..349964.69 rows=595218 width=40) (actual time=1005.440..6856.568 rows=1188904 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=5509 read=206918 written=144 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.422..4144.825 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=5495 read=165519 written=117 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.041..0.376 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54318.17..54318.17 rows=297609 width=40) (actual time=1001.498..1001.498 rows=297402 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25640kB Buffers: shared hit=14 read=41399 written=27 -> Bitmap Heap Scan on part (cost=5772.85..54318.17 rows=297609 width=40) (actual time=76.730..864.439 rows=297402 loops=1) Recheck Cond: (p_size = ANY ('{40,4,41,10,38,3,14,5}'::integer[])) Filter: ((p_brand <> 'Brand#35'::bpchar) AND ((p_type)::text !~~ 'PROMO BRUSHED%'::text)) Rows Removed by Filter: 22978 Heap Blocks: exact=40513 Buffers: shared hit=14 read=41399 written=27 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5698.45 rows=320933 width=0) (actual time=67.297..67.297 rows=320380 loops=1) Index Cond: (p_size = ANY ('{40,4,41,10,38,3,14,5}'::integer[])) Buffers: shared hit=12 read=888 written=1 Planning time: 4.324 ms Execution time: 10582.047 ms (35 rows) COMMIT; COMMIT