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#14' and p_type not like 'ECONOMY BRUSHED%' and p_size in (40, 23, 15, 41, 27, 2, 6, 4) 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=456094.25..456163.47 rows=27687 width=40) (actual time=36672.680..36674.331 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=85 read=212357 -> GroupAggregate (cost=446391.30..454051.37 rows=27687 width=40) (actual time=35660.607..36337.701 rows=27839 loops=1) Buffers: shared hit=69 read=212357 -> Sort (cost=446391.30..447867.94 rows=590656 width=40) (actual time=35660.424..35827.880 rows=1184994 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141730kB Buffers: shared hit=69 read=212357 -> Hash Join (cost=57906.58..389771.14 rows=590656 width=40) (actual time=826.113..8831.876 rows=1184994 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=69 read=212357 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.385..3418.243 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=57 read=170958 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.151..1.288 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54206.50..54206.50 rows=295328 width=40) (actual time=824.419..824.419 rows=296423 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21440kB Buffers: shared hit=12 read=41399 -> Bitmap Heap Scan on part (cost=5724.18..54206.50 rows=295328 width=40) (actual time=84.558..717.299 rows=296423 loops=1) Recheck Cond: (p_size = ANY ('{40,23,15,41,27,2,6,4}'::integer[])) Filter: ((p_brand <> 'Brand#14'::bpchar) AND ((p_type)::text !~~ 'ECONOMY BRUSHED%'::text)) Rows Removed by Filter: 23036 Buffers: shared hit=12 read=41399 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5650.35 rows=318413 width=0) (actual time=74.923..74.923 rows=319459 loops=1) Index Cond: (p_size = ANY ('{40,23,15,41,27,2,6,4}'::integer[])) Buffers: shared hit=10 read=886 Total runtime: 36686.963 ms (32 rows) COMMIT; COMMIT