QUERY PLAN
Limit (cost=1206.48..1206.49 rows=1 width=418)
-> Sort (cost=1206.48..1206.49 rows=1 width=418)
Sort Key: (CASE WHEN (p.erp_sales_amount <> '0'::numeric) THEN (p.erp_j_profit_amount / p.erp_sales_amount) ELSE NULL::numeric END) DESC NULLS LAST, p.updated_at DESC
-> Hash Left Join (cost=1019.42..1206.47 rows=1 width=418)
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=1010.25..1196.96 rows=116 width=409)
Hash Cond: (c.id = p.client_id)
-> Seq Scan on tbl_clients c (cost=0.00..178.31 rows=1931 width=59)
-> Hash (cost=1008.80..1008.80 rows=116 width=354)
-> Subquery Scan on p (cost=991.11..1008.80 rows=116 width=354)
-> GroupAggregate (cost=991.11..1007.64 rows=116 width=390)
Group Key: p_1.id, r.user_id, (sum(r.pct))
-> Sort (cost=991.11..991.40 rows=116 width=354)
Sort Key: p_1.id, r.user_id, (sum(r.pct))
-> Hash Left Join (cost=943.38..987.13 rows=116 width=354)
Hash Cond: (p_1.id = esgs.project_id)
-> Hash Left Join (cost=940.26..983.70 rows=116 width=322)
Hash Cond: (p_1.id = eccrta.project_id)
-> Hash Right Join (cost=853.71..896.85 rows=116 width=290)
Hash Cond: (sc_1.from_project = p_1.id)
-> HashAggregate (cost=541.11..561.35 rows=1619 width=36)
Group Key: sc_1.from_project
-> Hash Join (cost=84.26..504.49 rows=7325 width=9)
Hash Cond: (t.sales_contract_id = sc_1.id)
-> Seq Scan on tbl_erp_cash_cost_tickets t (cost=0.00..400.68 rows=7445 width=9)
Filter: (status = 2)
-> Hash (cost=63.71..63.71 rows=1644 width=8)
-> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..63.71 rows=1644 width=8)
Filter: (from_project IS NOT NULL)
-> Hash (cost=311.15..311.15 rows=116 width=258)
-> Hash Left Join (cost=239.91..311.15 rows=116 width=258)
Hash Cond: (p_1.id = ecta.project_id)
-> Hash Left Join (cost=238.56..309.49 rows=116 width=226)
Hash Cond: (p_1.id = o.project_id)
-> Hash Right Join (cost=235.39..306.01 rows=116 width=162)
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=162)
-> Hash Right Join (cost=218.68..233.94 rows=116 width=162)
Hash Cond: (t_1.project_id = p_1.id)
-> HashAggregate (cost=25.64..33.23 rows=607 width=40)
Group Key: t_1.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_1.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_1 (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=126)
-> Seq Scan on tbl_projects p_1 (cost=0.00..191.59 rows=116 width=126)
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_2.project_id
-> Hash Right Join (cost=1.22..3.11 rows=4 width=13)
Hash Cond: (eipss.erp_sales_outbound_id = t_2.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_2 (cost=0.00..1.21 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Hash (cost=1.30..1.30 rows=4 width=36)
-> Subquery Scan on ecta (cost=1.21..1.30 rows=4 width=36)
-> HashAggregate (cost=1.21..1.26 rows=4 width=36)
Group Key: t_3.project_id
-> Seq Scan on tbl_erp_cost_tickets t_3 (cost=0.00..1.19 rows=5 width=9)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Hash (cost=86.36..86.36 rows=15 width=36)
-> Subquery Scan on eccrta (cost=85.91..86.36 rows=15 width=36)
-> GroupAggregate (cost=85.91..86.21 rows=15 width=36)
Group Key: sc_2.from_project
-> Sort (cost=85.91..85.95 rows=15 width=9)
Sort Key: sc_2.from_project
-> Nested Loop (cost=0.28..85.62 rows=15 width=9)
-> Seq Scan on tbl_erp_cost_convert_tickets t_4 (cost=0.00..1.19 rows=15 width=9)
Filter: (status = 2)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_2 (cost=0.28..5.63 rows=1 width=8)
Index Cond: (id = t_4.sales_contract_id)
Filter: (from_project IS NOT NULL)
-> Hash (cost=3.11..3.11 rows=1 width=36)
-> Subquery Scan on esgs (cost=3.09..3.11 rows=1 width=36)
-> HashAggregate (cost=3.09..3.10 rows=1 width=36)
Group Key: t_5.project_id
-> Hash Right Join (cost=1.16..3.04 rows=6 width=13)
Hash Cond: (eipss_1.erp_sales_gift_id = t_5.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..1.68 rows=68 width=13)
-> Hash (cost=1.15..1.15 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_gifts t_5 (cost=0.00..1.15 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)