| Aggregate (cost=1427.22..1427.23 rows=1 width=32) |
| -> Append (cost=687.51..1427.20 rows=8 width=32) |
| -> Aggregate (cost=687.51..687.52 rows=1 width=32) |
| -> Nested Loop Left Join (cost=521.56..687.51 rows=1 width=5) |
| Filter: ((NOT (hashed SubPlan 1)) OR (t.sales_contract_id IS NULL)) |
| -> Hash Join (cost=508.39..666.30 rows=1 width=9) |
| Hash Cond: (am.erp_cash_cost_ticket_id = t.id) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_handlers am (cost=0.00..136.09 rows=8309 width=9) |
| -> Hash (cost=508.38..508.38 rows=1 width=8) |
| -> Seq Scan on tbl_erp_cash_cost_tickets t (cost=0.00..508.38 rows=1 width=8) |
| Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc (cost=0.28..8.29 rows=1 width=8) |
| Index Cond: (id = t.sales_contract_id) |
| SubPlan 1 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_12.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_12.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_12 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=543.72..543.73 rows=1 width=32) |
| -> Nested Loop (cost=13.19..543.71 rows=1 width=10) |
| Join Filter: (pd.id = am_1.erp_profit_distribute_id) |
| -> Nested Loop (cost=13.19..542.53 rows=1 width=9) |
| Join Filter: (pd.project_id = sc_1.from_project) |
| -> Hash Join (cost=12.91..25.83 rows=1 width=12) |
| Hash Cond: (pd.project_id = t_2.project_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd (cost=0.00..12.30 rows=230 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_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)) |
| -> Nested Loop (cost=0.28..516.68 rows=1 width=9) |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..508.38 rows=1 width=9) |
| Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_1 (cost=0.28..8.29 rows=1 width=8) |
| Index Cond: (id = t_1.sales_contract_id) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_1 (cost=0.00..1.08 rows=8 width=9) |
| -> Aggregate (cost=19.18..19.19 rows=1 width=32) |
| -> Hash Join (cost=17.55..19.18 rows=1 width=32) |
| Hash Cond: (am_2.erp_cost_ticket_id = t_3.id) |
| -> Seq Scan on tbl_erp_cost_ticket_handlers am_2 (cost=0.00..1.49 rows=49 width=36) |
| -> Hash (cost=17.54..17.54 rows=1 width=4) |
| -> Seq Scan on tbl_erp_cost_tickets t_3 (cost=12.89..17.54 rows=1 width=4) |
| Filter: (((NOT (hashed SubPlan 2)) OR (project_id IS NULL)) AND (created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| SubPlan 2 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_13.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_13.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_13 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=31.47..31.48 rows=1 width=32) |
| -> Nested Loop (cost=12.91..31.46 rows=1 width=10) |
| Join Filter: (pd_1.project_id = t_4.project_id) |
| -> Nested Loop (cost=12.91..27.01 rows=1 width=13) |
| Join Filter: (pd_1.id = am_3.erp_profit_distribute_id) |
| -> Hash Join (cost=12.91..25.83 rows=1 width=12) |
| Hash Cond: (pd_1.project_id = t_5.project_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd_1 (cost=0.00..12.30 rows=230 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_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)) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_3 (cost=0.00..1.08 rows=8 width=9) |
| -> Seq Scan on tbl_erp_cost_tickets t_4 (cost=0.00..4.44 rows=1 width=9) |
| Filter: ((created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Aggregate (cost=24.08..24.09 rows=1 width=32) |
| -> Hash Join (cost=22.39..24.07 rows=3 width=32) |
| Hash Cond: (am_4.erp_cost_convert_ticket_id = t_6.id) |
| -> Seq Scan on tbl_erp_cost_convert_ticket_handlers am_4 (cost=0.00..1.49 rows=49 width=36) |
| -> Hash (cost=22.38..22.38 rows=1 width=4) |
| -> Nested Loop Left Join (cost=13.17..22.38 rows=1 width=4) |
| Filter: ((NOT (hashed SubPlan 3)) OR (t_6.sales_contract_id IS NULL)) |
| -> Seq Scan on tbl_erp_cost_convert_tickets t_6 (cost=0.00..1.18 rows=1 width=8) |
| Filter: ((created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> 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 = t_6.sales_contract_id) |
| SubPlan 3 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_14.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_14.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_14 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=36.51..36.52 rows=1 width=32) |
| -> Nested Loop (cost=13.19..36.50 rows=1 width=37) |
| Join Filter: (pd_2.id = am_5.erp_profit_distribute_id) |
| -> Nested Loop (cost=13.19..35.32 rows=1 width=36) |
| Join Filter: (pd_2.project_id = sc_3.from_project) |
| -> Hash Join (cost=12.91..25.83 rows=1 width=12) |
| Hash Cond: (pd_2.project_id = t_8.project_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd_2 (cost=0.00..12.30 rows=230 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_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)) |
| -> Nested Loop (cost=0.28..9.48 rows=1 width=36) |
| -> Seq Scan on tbl_erp_cost_convert_tickets t_7 (cost=0.00..1.18 rows=1 width=36) |
| Filter: ((created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 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 = t_7.sales_contract_id) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_5 (cost=0.00..1.08 rows=8 width=9) |
| -> Aggregate (cost=35.36..35.37 rows=1 width=32) |
| -> Hash Right Join (cost=21.37..35.34 rows=4 width=9) |
| Hash Cond: (eipss.erp_sales_gift_id = t_9.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=21.36..21.36 rows=1 width=4) |
| -> Seq Scan on tbl_erp_sales_gifts t_9 (cost=12.89..21.36 rows=1 width=4) |
| Filter: (((NOT (hashed SubPlan 4)) OR (project_id IS NULL)) AND (created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| SubPlan 4 |
| -> Group (cost=12.88..12.89 rows=1 width=4) |
| Group Key: t_15.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_15.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_15 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=49.20..49.21 rows=1 width=32) |
| -> Nested Loop (cost=21.08..49.19 rows=1 width=14) |
| Join Filter: (pd_3.id = am_6.erp_profit_distribute_id) |
| -> Nested Loop (cost=21.08..48.01 rows=1 width=13) |
| Join Filter: (pd_3.project_id = t_10.project_id) |
| -> Hash Join (cost=12.91..25.83 rows=1 width=12) |
| Hash Cond: (pd_3.project_id = t_11.project_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd_3 (cost=0.00..12.30 rows=230 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_11.project_id |
| -> Sort (cost=12.88..12.89 rows=1 width=4) |
| Sort Key: t_11.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_11 (cost=0.00..12.88 rows=1 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Hash Right Join (cost=8.16..22.13 rows=4 width=13) |
| Hash Cond: (eipss_1.erp_sales_gift_id = t_10.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=8.15..8.15 rows=1 width=8) |
| -> Seq Scan on tbl_erp_sales_gifts t_10 (cost=0.00..8.15 rows=1 width=8) |
| Filter: ((created_at >= '2026-11-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-11-30 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_6 (cost=0.00..1.08 rows=8 width=9) |