| Aggregate (cost=1200.45..1200.46 rows=1 width=8) |
| -> Sort (cost=1200.33..1200.35 rows=8 width=301) |
| Sort Key: "*SELECT* 1".created_at DESC |
| -> Result (cost=13.46..1200.21 rows=8 width=301) |
| -> Append (cost=13.46..1200.13 rows=8 width=8) |
| -> Subquery Scan on "*SELECT* 1" (cost=13.46..358.99 rows=1 width=8) |
| -> Nested Loop Left Join (cost=13.46..358.98 rows=1 width=301) |
| Filter: ((NOT (hashed SubPlan 1)) OR (r.sales_contract_id IS NULL)) |
| -> Nested Loop (cost=0.29..344.41 rows=1 width=12) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_handlers am (cost=0.00..156.86 rows=24 width=4) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets r (cost=0.29..7.81 rows=1 width=16) |
| Index Cond: (id = am.erp_cash_cost_ticket_id) |
| Filter: (is_payment_settle AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc (cost=0.28..1.66 rows=1 width=8) |
| Index Cond: (id = r.sales_contract_id) |
| SubPlan 1 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_3.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_3.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_3 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 2" (cost=13.06..657.61 rows=1 width=8) |
| -> Nested Loop (cost=13.06..657.60 rows=1 width=301) |
| Join Filter: (sc_1.id = r_1.sales_contract_id) |
| -> Nested Loop (cost=13.06..145.05 rows=1 width=4) |
| Join Filter: (sc_1.from_project = pd.project_id) |
| -> Hash Join (cost=12.91..135.70 rows=1 width=12) |
| Hash Cond: (sc_1.from_project = t.project_id) |
| -> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..118.25 rows=1725 width=8) |
| -> Hash (cost=12.90..12.90 rows=1 width=4) |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=4) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_1 (cost=0.00..1.10 rows=1 width=4) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_erp_profit_distributes_pkey on tbl_erp_profit_distributes pd (cost=0.14..8.16 rows=1 width=8) |
| Index Cond: (id = am_1.erp_profit_distribute_id) |
| -> Seq Scan on tbl_erp_cash_cost_tickets r_1 (cost=0.00..508.38 rows=334 width=12) |
| Filter: (is_payment_settle AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 3" (cost=12.89..19.48 rows=1 width=8) |
| -> Nested Loop (cost=12.89..19.47 rows=1 width=301) |
| Join Filter: (r_2.id = am_2.erp_cost_ticket_id) |
| -> Seq Scan on tbl_erp_cost_ticket_handlers am_2 (cost=0.00..1.61 rows=1 width=4) |
| Filter: (user_id = 1003) |
| -> Seq Scan on tbl_erp_cost_tickets r_2 (cost=12.89..17.74 rows=9 width=12) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND ((NOT (hashed SubPlan 2)) OR (project_id IS NULL)) AND (status = 2)) |
| SubPlan 2 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_4.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_4.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_4 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 4" (cost=13.03..27.06 rows=1 width=8) |
| -> Nested Loop (cost=13.03..27.05 rows=1 width=301) |
| Join Filter: (pd_1.project_id = t_1.project_id) |
| -> Nested Loop (cost=0.14..14.13 rows=1 width=16) |
| Join Filter: (pd_1.project_id = r_3.project_id) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=4) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_3 (cost=0.00..1.10 rows=1 width=4) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_erp_profit_distributes_pkey on tbl_erp_profit_distributes pd_1 (cost=0.14..8.16 rows=1 width=8) |
| Index Cond: (id = am_3.erp_profit_distribute_id) |
| -> Seq Scan on tbl_erp_cost_tickets r_3 (cost=0.00..4.64 rows=13 width=12) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2)) |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_1.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_1.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_1 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 5" (cost=13.17..24.01 rows=1 width=8) |
| -> Nested Loop Left Join (cost=13.17..24.00 rows=1 width=301) |
| Filter: ((NOT (hashed SubPlan 3)) OR (r_4.sales_contract_id IS NULL)) |
| -> Nested Loop (cost=0.00..2.80 rows=1 width=12) |
| Join Filter: (r_4.id = am_4.erp_cost_convert_ticket_id) |
| -> Seq Scan on tbl_erp_cost_convert_tickets r_4 (cost=0.00..1.18 rows=1 width=16) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Seq Scan on tbl_erp_cost_convert_ticket_handlers am_4 (cost=0.00..1.61 rows=1 width=4) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_2 (cost=0.28..8.29 rows=1 width=8) |
| Index Cond: (id = r_4.sales_contract_id) |
| SubPlan 3 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_5.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_5.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_5 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 6" (cost=13.31..31.75 rows=1 width=8) |
| -> Nested Loop (cost=13.31..31.74 rows=1 width=301) |
| Join Filter: (pd_2.project_id = t_2.project_id) |
| -> Nested Loop (cost=0.42..18.82 rows=1 width=16) |
| Join Filter: (sc_3.from_project = pd_2.project_id) |
| -> Nested Loop (cost=0.28..9.48 rows=1 width=12) |
| -> Seq Scan on tbl_erp_cost_convert_tickets r_5 (cost=0.00..1.18 rows=1 width=12) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_3 (cost=0.28..8.29 rows=1 width=8) |
| Index Cond: (id = r_5.sales_contract_id) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=4) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_5 (cost=0.00..1.10 rows=1 width=4) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_erp_profit_distributes_pkey on tbl_erp_profit_distributes pd_2 (cost=0.14..8.16 rows=1 width=8) |
| Index Cond: (id = am_5.erp_profit_distribute_id) |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_2.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_2.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_2 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 7" (cost=35.68..35.72 rows=1 width=8) |
| -> GroupAggregate (cost=35.68..35.71 rows=1 width=301) |
| Group Key: r_6.id |
| -> Sort (cost=35.68..35.69 rows=4 width=12) |
| Sort Key: r_6.id |
| -> Hash Right Join (cost=21.68..35.64 rows=4 width=12) |
| Hash Cond: (eipss.erp_sales_gift_id = r_6.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=551 width=4) |
| -> Hash (cost=21.66..21.66 rows=1 width=12) |
| -> Seq Scan on tbl_erp_sales_gifts r_6 (cost=12.89..21.66 rows=1 width=12) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND ((NOT (hashed SubPlan 4)) OR (project_id IS NULL)) AND (status = 2) AND (handler = 1003)) |
| SubPlan 4 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_6.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_6.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_6 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 8" (cost=45.48..45.51 rows=1 width=8) |
| -> GroupAggregate (cost=45.48..45.50 rows=1 width=306) |
| Group Key: r_7.id, am_6.user_id, am_6.pct |
| -> Sort (cost=45.48..45.48 rows=1 width=21) |
| Sort Key: r_7.id, am_6.pct |
| -> Hash Right Join (cost=30.88..45.47 rows=1 width=21) |
| Hash Cond: (eipss_1.erp_sales_gift_id = r_7.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.51 rows=551 width=4) |
| -> Hash (cost=30.87..30.87 rows=1 width=21) |
| -> Hash Join (cost=22.24..30.87 rows=1 width=21) |
| Hash Cond: (r_7.project_id = pd_3.project_id) |
| -> Seq Scan on tbl_erp_sales_gifts r_7 (cost=12.89..21.36 rows=42 width=16) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND ((NOT (hashed SubPlan 5)) OR (project_id IS NULL)) AND (status = 2)) |
| SubPlan 5 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_7.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_7.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_7 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Hash (cost=9.33..9.33 rows=1 width=13) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=13) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_6 (cost=0.00..1.10 rows=1 width=13) |
| Filter: (user_id = 1003) |
| -> Index Scan using tbl_erp_profit_distributes_pkey on tbl_erp_profit_distributes pd_3 (cost=0.14..8.16 rows=1 width=8) |
| Index Cond: (id = am_6.erp_profit_distribute_id) |