| Limit (cost=1284.50..1284.53 rows=10 width=223) |
| -> Sort (cost=1284.50..1284.53 rows=10 width=223) |
| Sort Key: r.created_at DESC |
| -> Append (cost=13.46..1284.33 rows=10 width=223) |
| -> Nested Loop Left Join (cost=13.46..358.98 rows=1 width=155) |
| Filter: ((NOT (hashed SubPlan 1)) OR (r.sales_contract_id IS NULL)) |
| -> Nested Loop (cost=0.29..344.41 rows=1 width=107) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_handlers am (cost=0.00..156.86 rows=24 width=13) |
| 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=98) |
| 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_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)) |
| -> Nested Loop (cost=13.06..657.62 rows=1 width=182) |
| Join Filter: (sc_1.id = r_1.sales_contract_id) |
| -> Nested Loop (cost=13.06..145.05 rows=1 width=13) |
| 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=13) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_1 (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 (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=103) |
| Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) 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 (status = 2)) |
| -> Nested Loop (cost=12.89..19.47 rows=1 width=193) |
| 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=40) |
| Filter: (user_id = 1003) |
| -> Seq Scan on tbl_erp_cost_tickets r_2 (cost=12.89..17.74 rows=9 width=116) |
| 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_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)) |
| -> Nested Loop (cost=13.03..27.06 rows=1 width=193) |
| Join Filter: (pd_1.project_id = t_1.project_id) |
| -> Nested Loop (cost=0.14..14.13 rows=1 width=134) |
| Join Filter: (pd_1.project_id = r_3.project_id) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=13) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_3 (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_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=121) |
| 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)) |
| -> Nested Loop Left Join (cost=13.17..24.01 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=212) |
| 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=176) |
| 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=40) |
| 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_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)) |
| -> Nested Loop (cost=13.31..31.75 rows=1 width=301) |
| Join Filter: (pd_2.project_id = t_2.project_id) |
| -> Nested Loop (cost=0.42..18.82 rows=1 width=225) |
| Join Filter: (sc_3.from_project = pd_2.project_id) |
| -> Nested Loop (cost=0.28..9.48 rows=1 width=212) |
| -> Seq Scan on tbl_erp_cost_convert_tickets r_5 (cost=0.00..1.18 rows=1 width=208) |
| 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=13) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_5 (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_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)) |
| -> GroupAggregate (cost=35.68..35.75 rows=1 width=220) |
| Group Key: r_6.id |
| -> Sort (cost=35.68..35.69 rows=4 width=112) |
| Sort Key: r_6.id |
| -> Hash Right Join (cost=21.68..35.64 rows=4 width=112) |
| 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=13) |
| -> Hash (cost=21.66..21.66 rows=1 width=103) |
| -> Seq Scan on tbl_erp_sales_gifts r_6 (cost=12.89..21.66 rows=1 width=103) |
| 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_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)) |
| -> Subquery Scan on "*SELECT* 8" (cost=45.48..45.53 rows=1 width=220) |
| -> GroupAggregate (cost=45.48..45.52 rows=1 width=225) |
| Group Key: r_7.id, am_6.user_id, am_6.pct |
| -> Sort (cost=45.48..45.48 rows=1 width=117) |
| Sort Key: r_7.id, am_6.pct |
| -> Hash Right Join (cost=30.88..45.47 rows=1 width=117) |
| 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=13) |
| -> Hash (cost=30.87..30.87 rows=1 width=108) |
| -> Hash Join (cost=22.24..30.87 rows=1 width=108) |
| 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=99) |
| 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_8.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_8.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_8 (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) |
| -> GroupAggregate (cost=37.35..37.40 rows=1 width=236) |
| Group Key: r_8.id |
| -> Sort (cost=37.35..37.36 rows=4 width=120) |
| Sort Key: r_8.id |
| -> Hash Right Join (cost=23.33..37.31 rows=4 width=120) |
| Hash Cond: (eipss_2.erp_sales_outbound_id = r_8.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_2 (cost=0.00..12.51 rows=551 width=9) |
| -> Hash (cost=23.31..23.31 rows=1 width=115) |
| -> Seq Scan on tbl_erp_sales_outbounds r_8 (cost=12.89..23.31 rows=1 width=115) |
| 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 6)) OR (project_id IS NULL)) AND (status = 2) AND (handler = 1003)) |
| SubPlan 6 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_9.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_9.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_9 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 10" (cost=46.63..46.68 rows=1 width=236) |
| -> GroupAggregate (cost=46.63..46.67 rows=1 width=245) |
| Group Key: r_9.id, am_7.user_id, am_7.pct |
| -> Sort (cost=46.63..46.64 rows=1 width=129) |
| Sort Key: r_9.id, am_7.pct |
| -> Nested Loop (cost=22.83..46.62 rows=1 width=129) |
| Join Filter: (pd_4.project_id = r_9.project_id) |
| -> Nested Loop (cost=0.14..9.33 rows=1 width=13) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_7 (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_4 (cost=0.14..8.16 rows=1 width=8) |
| Index Cond: (id = am_7.erp_profit_distribute_id) |
| -> Hash Right Join (cost=22.68..37.28 rows=1 width=124) |
| Hash Cond: (eipss_3.erp_sales_outbound_id = r_9.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_3 (cost=0.00..12.51 rows=551 width=9) |
| -> Hash (cost=22.67..22.67 rows=1 width=119) |
| -> Hash Join (cost=12.91..22.67 rows=1 width=119) |
| Hash Cond: (r_9.project_id = t_3.project_id) |
| -> Seq Scan on tbl_erp_sales_outbounds r_9 (cost=0.00..9.66 rows=36 width=115) |
| 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)) |
| -> Hash (cost=12.90..12.90 rows=1 width=4) |
| -> 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)) |