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#45' and p_type not like 'LARGE BURNISHED%' and p_size in (25, 48, 37, 12, 16, 39, 19, 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=416647.89..416717.53 rows=27854 width=40) (actual time=8077.745..8079.577 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=206131 read=6308 -> GroupAggregate (cost=406885.30..414591.49 rows=27854 width=40) (actual time=7392.336..8029.787 rows=27839 loops=1) Group Key: part.p_brand, part.p_type, part.p_size Buffers: shared hit=206117 read=6308 -> Sort (cost=406885.30..408370.83 rows=594212 width=40) (actual time=7392.269..7526.054 rows=1187965 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141962kB Buffers: shared hit=206117 read=6308 -> Hash Join (cost=57998.41..349898.53 rows=594212 width=40) (actual time=651.150..5000.369 rows=1187965 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=206117 read=6308 -> Seq Scan on partsupp (cost=16.23..270974.23 rows=4000000 width=8) (actual time=0.401..3018.485 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=170901 read=113 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..15.98 rows=100 width=4) (actual time=0.039..0.356 rows=56 loops=1) Buffers: shared hit=55 read=1 -> Hash (cost=54268.36..54268.36 rows=297106 width=40) (actual time=648.372..648.372 rows=297165 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25594kB Buffers: shared hit=35216 read=6195 -> Bitmap Heap Scan on part (cost=5739.68..54268.36 rows=297106 width=40) (actual time=66.692..535.750 rows=297165 loops=1) Recheck Cond: (p_size = ANY ('{25,48,37,12,16,39,19,30}'::integer[])) Filter: ((p_brand <> 'Brand#45'::bpchar) AND ((p_type)::text !~~ 'LARGE BURNISHED%'::text)) Rows Removed by Filter: 22860 Heap Blocks: exact=40514 Buffers: shared hit=35216 read=6195 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5665.41 rows=320267 width=0) (actual time=57.936..57.936 rows=320025 loops=1) Index Cond: (p_size = ANY ('{25,48,37,12,16,39,19,30}'::integer[])) Buffers: shared hit=8 read=889 Planning time: 3.809 ms Execution time: 8089.835 ms (35 rows) COMMIT; COMMIT