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#55' and p_type not like 'LARGE BURNISHED%' and p_size in (18, 28, 12, 20, 8, 46, 10, 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=456609.91..456679.54 rows=27854 width=40) (actual time=52031.634..52036.012 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=19349 read=193092 written=4841 -> GroupAggregate (cost=446849.39..454553.50 rows=27854 width=40) (actual time=50745.174..51658.577 rows=27838 loops=1) Buffers: shared hit=19333 read=193092 written=4841 -> Sort (cost=446849.39..448334.50 rows=594046 width=40) (actual time=50745.049..51030.400 rows=1186800 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141871kB Buffers: shared hit=19333 read=193092 written=4841 -> Hash Join (cost=57981.28..389879.74 rows=594046 width=40) (actual time=2352.114..18796.651 rows=1186800 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=19333 read=193092 written=4841 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.348..8271.199 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=19324 read=151691 written=1409 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.136..1.239 rows=56 loops=1) Buffers: shared hit=55 read=2 -> Hash (cost=54258.95..54258.95 rows=297108 width=40) (actual time=2350.364..2350.364 rows=296866 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21473kB Buffers: shared hit=9 read=41401 written=3432 -> Bitmap Heap Scan on part (cost=5736.62..54258.95 rows=297108 width=40) (actual time=164.741..2089.621 rows=296866 loops=1) Recheck Cond: (p_size = ANY ('{18,28,12,20,8,46,10,30}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'LARGE BURNISHED%'::text)) Rows Removed by Filter: 22898 Buffers: shared hit=9 read=41401 written=3432 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5662.35 rows=320013 width=0) (actual time=147.477..147.477 rows=319764 loops=1) Index Cond: (p_size = ANY ('{18,28,12,20,8,46,10,30}'::integer[])) Buffers: shared hit=7 read=890 written=147 Total runtime: 52065.485 ms (32 rows) COMMIT; COMMIT