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#15' and p_type not like 'SMALL BURNISHED%' and p_size in (34, 12, 23, 49, 44, 9, 2, 30) 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=416659.62..416729.26 rows=27858 width=40) (actual time=9960.131..9963.427 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=101670 read=110770 written=3625 -> GroupAggregate (cost=406895.68..414602.89 rows=27858 width=40) (actual time=9188.079..9905.656 rows=27838 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=101656 read=110770 written=3625 -> Sort (cost=406895.68..408381.41 rows=594290 width=40) (actual time=9187.999..9345.011 rows=1185451 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141766kB Buffers: shared hit=101656 read=110770 written=3625 -> Hash Join (cost=57999.97..349900.87 rows=594290 width=40) (actual time=1035.381..6350.447 rows=1185451 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=101656 read=110770 written=3625 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.431..3647.717 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=101647 read=69367 written=3625 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..0.383 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54269.43..54269.43 rows=297145 width=40) (actual time=1031.670..1031.670 rows=296520 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25545kB Buffers: shared hit=9 read=41403 -> Bitmap Heap Scan on part (cost=5739.93..54269.43 rows=297145 width=40) (actual time=88.104..885.032 rows=296520 loops=1) Recheck Cond: (p_size = ANY ('{34,12,23,49,44,9,2,30}'::integer[])) Filter: ((p_brand <> 'Brand#15'::bpchar) AND ((p_type)::text !~~ 'SMALL BURNISHED%'::text)) Rows Removed by Filter: 23021 Heap Blocks: exact=40515 Buffers: shared hit=9 read=41403 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5665.65 rows=320300 width=0) (actual time=77.060..77.060 rows=319541 loops=1) Index Cond: (p_size = ANY ('{34,12,23,49,44,9,2,30}'::integer[])) Buffers: shared hit=7 read=890 Planning time: 4.286 ms Execution time: 9980.228 ms (35 rows) COMMIT; COMMIT