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 'LARGE POLISHED%' and p_size in (20, 30, 33, 44, 31, 42, 1, 23) 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=416711.99..416781.68 rows=27875 width=40) (actual time=12203.308..12208.500 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=11432 read=201007 written=310 -> GroupAggregate (cost=406941.99..414653.89 rows=27875 width=40) (actual time=11093.627..12146.091 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=11418 read=201007 written=310 -> Sort (cost=406941.99..408428.62 rows=594652 width=40) (actual time=11093.355..11468.395 rows=1187549 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141930kB Buffers: shared hit=11418 read=201007 written=310 -> Hash Join (cost=58005.33..349909.85 rows=594652 width=40) (actual time=1109.588..7108.655 rows=1187549 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=11418 read=201007 written=310 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.443..4251.235 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=8671 read=162343 written=15 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.397 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54272.52..54272.52 rows=297326 width=40) (actual time=1081.993..1081.993 rows=297053 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25598kB Buffers: shared hit=2747 read=38664 written=295 -> Bitmap Heap Scan on part (cost=5740.70..54272.52 rows=297326 width=40) (actual time=99.159..943.140 rows=297053 loops=1) Recheck Cond: (p_size = ANY ('{20,30,33,44,31,42,1,23}'::integer[])) Filter: ((p_brand <> 'Brand#15'::bpchar) AND ((p_type)::text !~~ 'LARGE POLISHED%'::text)) Rows Removed by Filter: 22990 Heap Blocks: exact=40512 Buffers: shared hit=2747 read=38664 written=295 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5666.37 rows=320393 width=0) (actual time=86.566..86.566 rows=320043 loops=1) Index Cond: (p_size = ANY ('{20,30,33,44,31,42,1,23}'::integer[])) Buffers: shared hit=9 read=890 written=17 Planning time: 4.761 ms Execution time: 12239.678 ms (35 rows) COMMIT; COMMIT