QUERY PLAN
GroupAggregate (cost=611.59..612.54 rows=42 width=44)
Group Key: c.project_id
-> Sort (cost=611.59..611.69 rows=43 width=20)
Sort Key: c.project_id
-> Hash Right Join (cost=567.24..610.42 rows=43 width=20)
Hash Cond: (tbl_pre_sales.case_id = c.id)
-> HashAggregate (cost=101.48..124.92 rows=1563 width=20)
Group Key: tbl_pre_sales.case_id
-> Seq Scan on tbl_pre_sales (cost=0.00..85.75 rows=1573 width=24)
Filter: (NOT is_draft)
-> Hash (cost=465.22..465.22 rows=43 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..465.22 rows=43 width=8)
Filter: ((case_type = 1) AND (project_id = ANY ('{3197,3927,3915,263,2914,3837,2939,3751,3934,3883,3930,3665,3150,3910,3922,3932,3911,3933,3895,3908}'::integer[])))