QUERY PLAN
GroupAggregate (cost=920.67..923.79 rows=128 width=44)
Group Key: c.client_id
-> Sort (cost=920.67..921.05 rows=152 width=20)
Sort Key: c.client_id
-> Hash Right Join (cost=744.07..915.16 rows=152 width=20)
Hash Cond: (tbl_implement_records.case_id = c.id)
-> HashAggregate (cost=376.02..468.91 rows=6193 width=20)
Group Key: tbl_implement_records.case_id
-> Seq Scan on tbl_implement_records (cost=0.00..311.03 rows=6499 width=24)
Filter: (NOT is_draft)
-> Hash (cost=366.15..366.15 rows=152 width=8)
-> Seq Scan on tbl_cases c (cost=0.00..366.15 rows=152 width=8)
Filter: ((case_type = 2) AND (client_id = ANY ('{1661,146,982,2538,2616,1933,3081,3372,3364,3344}'::integer[])))