QUERY PLAN
Sort (cost=40.32..40.33 rows=1 width=43)
Sort Key: p.bargain_date DESC
-> Group (cost=40.30..40.31 rows=1 width=43)
Group Key: p.id
-> Sort (cost=40.30..40.31 rows=1 width=43)
Sort Key: p.id
-> Nested Loop Anti Join (cost=5.51..40.29 rows=1 width=43)
Join Filter: (t.project_id = p.id)
-> Bitmap Heap Scan on tbl_projects p (cost=4.30..11.60 rows=1 width=43)
Recheck Cond: (client_id = 2836)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.29 rows=2 width=0)
Index Cond: (client_id = 2836)
-> Hash Right Join (cost=1.21..21.10 rows=607 width=4)
Hash Cond: (r.erp_profit_distribute_id = t.id)
-> Seq Scan on tbl_erp_profit_distribute_pcts r (cost=0.00..17.80 rows=780 width=4)
-> Hash (cost=1.12..1.12 rows=7 width=8)
-> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..1.12 rows=7 width=8)
Filter: ((project_id IS NOT NULL) AND (status = ANY ('{2,5,1}'::integer[])))