QUERY PLAN
Aggregate (cost=277.93..277.94 rows=1 width=8)
-> Sort (cost=270.02..271.34 rows=527 width=726)
Sort Key: p.bargain_date DESC, p.updated_at DESC
-> Subquery Scan on p (cost=235.66..246.20 rows=527 width=726)
-> HashAggregate (cost=235.66..240.93 rows=527 width=762)
Group Key: p_1.id, r.user_id, (sum(r.pct))
-> Hash Right Join (cost=216.45..231.70 rows=527 width=60)
Hash Cond: (t.project_id = p_1.id)
-> HashAggregate (cost=25.64..33.23 rows=607 width=40)
Group Key: t.project_id, r.user_id
-> Hash Right Join (cost=1.20..21.09 rows=607 width=40)
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=40)
-> Hash (cost=1.11..1.11 rows=7 width=8)
-> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..1.11 rows=7 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Hash (cost=184.22..184.22 rows=527 width=24)
-> Seq Scan on tbl_projects p_1 (cost=0.00..184.22 rows=527 width=24)
Filter: ((collected < budget) AND (project_status = 3))