QUERY PLAN
GroupAggregate (cost=630.25..630.85 rows=27 width=44)
Group Key: c.project_id
-> Sort (cost=630.25..630.31 rows=27 width=20)
Sort Key: c.project_id
-> Hash Right Join (cost=584.91..629.60 rows=27 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=479.99..479.99 rows=27 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..479.99 rows=27 width=8)
Filter: ((case_type = 1) AND (project_id = ANY ('{1929,1925,1791,1018,1111,1460,1240,986,983,887,884,883,778,764,861,88,4179,4175}'::integer[])))