QUERY PLAN
GroupAggregate (cost=529.71..530.82 rows=48 width=44)
Group Key: c.client_id
-> Sort (cost=529.71..529.83 rows=51 width=20)
Sort Key: c.client_id
-> Hash Right Join (cost=484.39..528.26 rows=51 width=20)
Hash Cond: (tbl_pre_sales.case_id = c.id)
-> HashAggregate (cost=102.98..126.80 rows=1588 width=20)
Group Key: tbl_pre_sales.case_id
-> Seq Scan on tbl_pre_sales (cost=0.00..87.00 rows=1598 width=24)
Filter: (NOT is_draft)
-> Hash (cost=380.77..380.77 rows=51 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..380.77 rows=51 width=8)
Filter: ((case_type = 1) AND (client_id = ANY ('{518,531,1225,3284,2186,3312,141,304,2146,24}'::integer[])))