QUERY PLAN
GroupAggregate (cost=527.88..528.08 rows=9 width=44)
Group Key: c.project_id
-> Sort (cost=527.88..527.90 rows=9 width=20)
Sort Key: c.project_id
-> Hash Right Join (cost=483.87..527.74 rows=9 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=9 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..380.77 rows=9 width=8)
Filter: ((case_type = 1) AND (project_id = ANY ('{2587,3933,3935,3788,3772,3737,3642,3392,3364,3258}'::integer[])))