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 'SMALL PLATED%' and p_size in (13, 4, 31, 22, 12, 46, 18, 5) 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=455891.63..455960.94 rows=27726 width=40) (actual time=35113.444..35115.135 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=85 read=212359 -> GroupAggregate (cost=446206.66..453845.59 rows=27726 width=40) (actual time=34166.265..34782.420 rows=27838 loops=1) Buffers: shared hit=69 read=212359 -> Sort (cost=446206.66..447678.99 rows=588934 width=40) (actual time=34166.163..34297.430 rows=1185486 loops=1) Sort Key: part.p_brand, part.p_type, part.p_size Sort Method: quicksort Memory: 141769kB Buffers: shared hit=69 read=212359 -> Hash Join (cost=57916.63..389763.97 rows=588934 width=40) (actual time=871.375..7322.924 rows=1185486 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=69 read=212359 -> Seq Scan on partsupp (cost=8.48..270966.48 rows=4000000 width=8) (actual time=1.346..3712.655 rows=7995520 loops=1) Filter: (NOT (hashed SubPlan 1)) Rows Removed by Filter: 4480 Buffers: shared hit=56 read=170959 SubPlan 1 -> Index Scan using supplier_s_suppkey_idx_like on supplier (cost=0.00..8.45 rows=10 width=4) (actual time=0.087..1.246 rows=56 loops=1) Buffers: shared hit=54 read=3 -> Hash (cost=54211.36..54211.36 rows=295743 width=40) (actual time=869.688..869.688 rows=296545 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21490kB Buffers: shared hit=13 read=41400 -> Bitmap Heap Scan on part (cost=5725.36..54211.36 rows=295743 width=40) (actual time=86.994..765.621 rows=296545 loops=1) Recheck Cond: (p_size = ANY ('{13,4,31,22,12,46,18,5}'::integer[])) Filter: ((p_brand <> 'Brand#55'::bpchar) AND ((p_type)::text !~~ 'SMALL PLATED%'::text)) Rows Removed by Filter: 22758 Buffers: shared hit=13 read=41400 -> Bitmap Index Scan on part_p_size_idx (cost=0.00..5651.43 rows=318560 width=0) (actual time=77.283..77.283 rows=319303 loops=1) Index Cond: (p_size = ANY ('{13,4,31,22,12,46,18,5}'::integer[])) Buffers: shared hit=11 read=886 Total runtime: 35127.418 ms (32 rows) COMMIT; COMMIT