QUERY PLAN
Aggregate (cost=515.64..515.65 rows=1 width=8)
-> Sort (cost=514.82..514.95 rows=55 width=726)
Sort Key: (CASE WHEN (p.erp_sales_amount <> '0'::numeric) THEN (p.erp_profit_amount / p.erp_sales_amount) ELSE NULL::numeric END) DESC NULLS LAST, p.updated_at DESC
-> Hash Left Join (cost=325.91..513.23 rows=55 width=726)
Hash Cond: (p.created_by = u2.id)
Filter: (((c.name)::text ~~* '%北京%'::text) OR (c.pinyin_shortcut ~~* '%北京%'::text) OR (p.pinyin_shortcut ~~* '%北京%'::text) OR ((p.project_title)::text ~~* '%北京%'::text) OR ((u2.name)::text ~~* '%北京%'::text))
-> Hash Right Join (cost=316.74..503.45 rows=116 width=162)
Hash Cond: (c.id = p.client_id)
-> Seq Scan on tbl_clients c (cost=0.00..178.31 rows=1931 width=59)
-> Hash (cost=315.29..315.29 rows=116 width=111)
-> Subquery Scan on p (cost=311.23..315.29 rows=116 width=111)
-> HashAggregate (cost=311.23..314.13 rows=116 width=423)
Group Key: p_1.id, r.user_id, (sum(r.pct))
-> Hash Left Join (cost=238.56..309.49 rows=116 width=151)
Hash Cond: (p_1.id = o.project_id)
-> Hash Right Join (cost=235.39..306.01 rows=116 width=87)
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=233.94..233.94 rows=116 width=87)
-> Hash Right Join (cost=218.68..233.94 rows=116 width=87)
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=116 width=51)
-> Seq Scan on tbl_projects p_1 (cost=0.00..191.59 rows=116 width=51)
Filter: ((bargain_date >= '2025-01-01'::date) AND (bargain_date <= '2025-12-31'::date) AND (project_status = 3))
-> Hash (cost=3.16..3.16 rows=1 width=68)
-> Subquery Scan on o (cost=3.14..3.16 rows=1 width=68)
-> HashAggregate (cost=3.14..3.15 rows=1 width=68)
Group Key: t_1.project_id
-> Hash Right Join (cost=1.22..3.11 rows=4 width=13)
Hash Cond: (eipss.erp_sales_outbound_id = t_1.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..1.68 rows=68 width=13)
-> Hash (cost=1.21..1.21 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_outbounds t_1 (cost=0.00..1.21 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Hash (cost=7.41..7.41 rows=141 width=13)
-> Seq Scan on tbl_users u2 (cost=0.00..7.41 rows=141 width=13)