QUERY PLAN
GroupAggregate (cost=655.71..658.05 rows=98 width=44)
Group Key: c.client_id
-> Sort (cost=655.71..655.99 rows=111 width=20)
Sort Key: c.client_id
-> Hash Right Join (cost=607.24..651.94 rows=111 width=20)
Hash Cond: (tbl_pre_sales.case_id = c.id)
-> HashAggregate (cost=104.58..128.85 rows=1618 width=20)
Group Key: tbl_pre_sales.case_id
-> Seq Scan on tbl_pre_sales (cost=0.00..88.30 rows=1628 width=24)
Filter: (NOT is_draft)
-> Hash (cost=501.27..501.27 rows=111 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..501.27 rows=111 width=8)
Filter: ((case_type = 1) AND (client_id = ANY ('{3354,399,2616,2538,146,1661,982,2166,1301,3330,2182,3411,304,402,3367,2242,3400,3342,3381,2699}'::integer[])))