QUERY PLAN
Aggregate (cost=231.56..231.57 rows=1 width=8)
-> Sort (cost=229.95..230.22 rows=107 width=662)
Sort Key: p.bargain_date DESC, p.updated_at DESC
-> Subquery Scan on p (cost=224.21..226.35 rows=107 width=662)
-> HashAggregate (cost=224.21..225.28 rows=107 width=698)
Group Key: p_1.id, pd.user_id, pd.pct
-> Hash Left Join (cost=33.05..223.40 rows=107 width=60)
Hash Cond: (p_1.id = pd.project_id)
-> Seq Scan on tbl_projects p_1 (cost=0.00..189.94 rows=107 width=24)
Filter: ((bargain_date >= '2025-01-01'::date) AND (bargain_date <= '2025-12-31'::date) AND (project_status = 3))
-> Hash (cost=33.01..33.01 rows=3 width=40)
-> Subquery Scan on pd (cost=32.92..33.01 rows=3 width=40)
-> GroupAggregate (cost=32.92..32.98 rows=3 width=40)
Group Key: t.project_id, r.user_id
-> Sort (cost=32.92..32.92 rows=3 width=40)
Sort Key: t.project_id, r.user_id
-> Hash Right Join (cost=13.01..32.89 rows=3 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=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))