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#43' and p_type not like 'ECONOMY BRUSHED%' and p_size in (19, 18, 38, 36, 1, 48, 44, 47) 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=416612.93..416682.54 rows=27844 width=40) (actual time=8934.283..8935.936 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=83 read=212363 -> GroupAggregate (cost=406854.02..414557.33 rows=27844 width=40) (actual time=8255.446..8886.859 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=69 read=212363 -> Sort (cost=406854.02..408338.99 rows=593990 width=40) (actual time=8255.376..8387.046 rows=1188008 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141966kB Buffers: shared hit=69 read=212363 -> Hash Join (cost=57992.24..349890.14 rows=593990 width=40) (actual time=943.011..5918.363 rows=1188008 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=69 read=212363 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=1.264..3645.936 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=57 read=170957 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.060..1.161 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54263.58..54263.58 rows=296995 width=40) (actual time=937.750..937.750 rows=297174 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25592kB Buffers: shared hit=12 read=41406 -> Bitmap Heap Scan on part (cost=5738.58..54263.58 rows=296995 width=40) (actual time=70.128..817.891 rows=297174 loops=1) Recheck Cond: (p_size = ANY ('{19,18,38,36,1,48,44,47}'::integer[])) Filter: ((p_brand <> 'Brand#43'::bpchar) AND ((p_type)::text !~~ 'ECONOMY BRUSHED%'::text)) Rows Removed by Filter: 23518 Heap Blocks: exact=40517 Buffers: shared hit=12 read=41406 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5664.33 rows=320120 width=0) (actual time=60.581..60.581 rows=320692 loops=1) Index Cond: (p_size = ANY ('{19,18,38,36,1,48,44,47}'::integer[])) Buffers: shared hit=10 read=891 Planning time: 6.974 ms Execution time: 8943.715 ms (35 rows) COMMIT; COMMIT