BEGIN; BEGIN EXPLAIN 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#34' and p_type not like 'LARGE BRUSHED%' and p_size in (50, 5, 44, 36, 12, 40, 41, 34) 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=319060.02..319444.52 rows=153799 width=44) Sort Key: (count(DISTINCT partsupp.ps_suppkey)) DESC, part.p_brand, part.p_type, part.p_size -> GroupAggregate (cost=224343.51..301077.71 rows=153799 width=44) Group Key: part.p_brand, part.p_type, part.p_size -> Gather Merge (cost=224343.51..293593.78 rows=594594 width=40) Workers Planned: 2 -> Sort (cost=223343.49..223962.86 rows=247748 width=40) Sort Key: part.p_brand, part.p_type, part.p_size -> Parallel Hash Join (cost=15212.52..194371.11 rows=247748 width=40) Hash Cond: (partsupp.ps_partkey = part.p_partkey) -> Parallel Index Only Scan using pk_partsupp on partsupp (cost=4.75..160795.46 rows=1666994 width=8) Filter: (NOT (hashed SubPlan 1)) SubPlan 1 -> Index Only Scan using supplier_s_suppkey_idx_like on supplier (cost=0.14..4.29 rows=10 width=4) -> Parallel Hash (cost=12691.62..12691.62 rows=123852 width=40) -> Parallel Index Only Scan using part_ios_test1 on part (cost=0.43..12691.62 rows=123852 width=40) Index Cond: (p_size = ANY ('{50,5,44,36,12,40,41,34}'::integer[])) Filter: ((p_brand <> 'Brand#34'::bpchar) AND ((p_type)::text !~~ 'LARGE BRUSHED%'::text)) (18 rows) COMMIT; COMMIT