QUERY PLAN
Aggregate (cost=354.55..354.56 rows=1 width=8)
-> Sort (cost=330.76..334.72 rows=1586 width=902)
Sort Key: p.updated_at DESC
-> HashAggregate (cost=230.59..246.45 rows=1586 width=902)
Group Key: p.id, pd.user_id, pd.pct
-> Hash Left Join (cost=37.62..218.69 rows=1586 width=48)
Hash Cond: (p.id = pd.project_id)
-> Seq Scan on tbl_projects p (cost=0.00..175.10 rows=1586 width=16)
Filter: (project_status = 3)
-> Hash (cost=37.55..37.55 rows=5 width=40)
-> Subquery Scan on pd (cost=37.39..37.55 rows=5 width=40)
-> GroupAggregate (cost=37.39..37.50 rows=5 width=40)
Group Key: t.project_id, r.user_id
-> Sort (cost=37.39..37.40 rows=5 width=40)
Sort Key: t.project_id, r.user_id
-> Hash Right Join (cost=13.01..37.33 rows=5 width=40)
Hash Cond: (r.erp_profit_distribute_id = t.id)
-> Seq Scan on tbl_erp_profit_distribute_pcts r (cost=0.00..21.30 rows=1130 width=40)
-> Hash (cost=13.00..13.00 rows=1 width=8)
-> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..13.00 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))