QUERY PLAN
Aggregate (cost=302.57..302.58 rows=1 width=8)
-> Sort (cost=302.55..302.55 rows=1 width=726)
Sort Key: p.bargain_date DESC, p.updated_at DESC
-> Subquery Scan on p (cost=302.51..302.54 rows=1 width=726)
-> GroupAggregate (cost=302.51..302.53 rows=1 width=698)
Group Key: p_1.id, r.user_id, (sum(r.pct))
-> Sort (cost=302.51..302.51 rows=1 width=60)
Sort Key: p_1.id, r.user_id, (sum(r.pct))
-> Hash Right Join (cost=232.51..302.50 rows=1 width=60)
Hash Cond: (sc.from_project = p_1.id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..63.71 rows=1671 width=4)
-> Hash (cost=232.50..232.50 rows=1 width=60)
-> Hash Right Join (cost=217.25..232.50 rows=1 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=191.59..191.59 rows=1 width=24)
-> Seq Scan on tbl_projects p_1 (cost=0.00..191.59 rows=1 width=24)
Filter: ((bargain_date >= '2025-09-15'::date) AND (bargain_date <= '2025-09-21'::date) AND (project_status = 3))