| Aggregate (cost=1167.02..1167.03 rows=1 width=32) |
| -> Append (cost=598.62..1166.99 rows=8 width=32) |
| -> Aggregate (cost=598.62..598.63 rows=1 width=32) |
| -> Hash Left Join (cost=440.73..597.91 rows=283 width=5) |
| Hash Cond: (t.sales_contract_id = sc.id) |
| Filter: ((NOT (hashed SubPlan 1)) OR (t.sales_contract_id IS NULL)) |
| -> Hash Join (cost=349.69..506.02 rows=323 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..134.84 rows=8184 width=9) |
| -> Hash (cost=345.50..345.50 rows=335 width=8) |
| -> Seq Scan on tbl_erp_cash_cost_tickets t (cost=0.00..345.50 rows=335 width=8) |
| 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)) |
| -> Hash (cost=68.32..68.32 rows=1732 width=8) |
| -> Seq Scan on tbl_sales_contracts sc (cost=0.00..68.32 rows=1732 width=8) |
| SubPlan 1 |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_12.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_12.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_12 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=426.04..426.05 rows=1 width=32) |
| -> Nested Loop (cost=1.11..426.03 rows=1 width=10) |
| Join Filter: (sc_1.id = t_1.sales_contract_id) |
| -> Nested Loop (cost=1.11..76.34 rows=1 width=9) |
| Join Filter: (pd.id = am_1.erp_profit_distribute_id) |
| -> Nested Loop (cost=1.11..75.16 rows=1 width=8) |
| Join Filter: (sc_1.from_project = pd.project_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd (cost=0.00..1.04 rows=4 width=8) |
| -> Materialize (cost=1.11..74.00 rows=2 width=12) |
| -> Hash Join (cost=1.11..73.99 rows=2 width=12) |
| Hash Cond: (sc_1.from_project = t_2.project_id) |
| -> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..68.32 rows=1732 width=8) |
| -> Hash (cost=1.09..1.09 rows=2 width=4) |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_2.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_2.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_2 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_1 (cost=0.00..1.08 rows=8 width=9) |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..345.50 rows=335 width=9) |
| 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)) |
| -> Aggregate (cost=6.13..6.14 rows=1 width=32) |
| -> Hash Join (cost=4.35..6.11 rows=8 width=5) |
| 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.59 rows=59 width=9) |
| -> Hash (cost=4.25..4.25 rows=8 width=4) |
| -> Seq Scan on tbl_erp_cost_tickets t_3 (cost=1.07..4.25 rows=8 width=4) |
| Filter: (((NOT (hashed SubPlan 2)) OR (project_id IS NULL)) 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)) |
| SubPlan 2 |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_13.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_13.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_13 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=6.46..6.47 rows=1 width=32) |
| -> Nested Loop (cost=1.11..6.45 rows=1 width=10) |
| Join Filter: (pd_1.id = am_3.erp_profit_distribute_id) |
| -> Nested Loop (cost=1.11..5.27 rows=1 width=9) |
| Join Filter: (t_4.project_id = pd_1.project_id) |
| -> Hash Join (cost=1.11..4.18 rows=1 width=13) |
| Hash Cond: (t_4.project_id = t_5.project_id) |
| -> Seq Scan on tbl_erp_cost_tickets t_4 (cost=0.00..3.03 rows=13 width=9) |
| 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=1.09..1.09 rows=2 width=4) |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_5.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_5.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_5 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Seq Scan on tbl_erp_profit_distributes pd_1 (cost=0.00..1.04 rows=4 width=8) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_3 (cost=0.00..1.08 rows=8 width=9) |
| -> Aggregate (cost=37.56..37.57 rows=1 width=32) |
| -> Hash Join (cost=35.55..37.50 rows=20 width=5) |
| 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.55 rows=55 width=9) |
| -> Hash (cost=35.50..35.50 rows=4 width=4) |
| -> Nested Loop Left Join (cost=1.35..35.50 rows=4 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.19 rows=4 width=8) |
| 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_2 (cost=0.28..8.29 rows=1 width=8) |
| Index Cond: (id = t_6.sales_contract_id) |
| SubPlan 3 |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_14.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_14.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_14 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=45.89..45.90 rows=1 width=32) |
| -> Nested Loop (cost=1.34..45.88 rows=1 width=11) |
| Join Filter: (pd_2.id = am_5.erp_profit_distribute_id) |
| -> Nested Loop (cost=1.34..44.70 rows=1 width=10) |
| Join Filter: (sc_3.from_project = pd_2.project_id) |
| -> Nested Loop (cost=1.34..43.61 rows=1 width=14) |
| Join Filter: (sc_3.from_project = t_8.project_id) |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_8.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_8.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_8 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Materialize (cost=0.28..42.41 rows=4 width=10) |
| -> Nested Loop (cost=0.28..42.39 rows=4 width=10) |
| -> Seq Scan on tbl_erp_cost_convert_tickets t_7 (cost=0.00..1.19 rows=4 width=10) |
| 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 = t_7.sales_contract_id) |
| -> Seq Scan on tbl_erp_profit_distributes pd_2 (cost=0.00..1.04 rows=4 width=8) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_5 (cost=0.00..1.08 rows=8 width=9) |
| -> Aggregate (cost=22.35..22.36 rows=1 width=32) |
| -> Hash Right Join (cost=7.22..21.36 rows=197 width=10) |
| Hash Cond: (eipss.erp_sales_gift_id = t_9.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.65 rows=565 width=14) |
| -> Hash (cost=6.65..6.65 rows=45 width=4) |
| -> Seq Scan on tbl_erp_sales_gifts t_9 (cost=1.07..6.65 rows=45 width=4) |
| Filter: (((NOT (hashed SubPlan 4)) OR (project_id IS NULL)) 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)) |
| SubPlan 4 |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_15.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_15.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_15 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Aggregate (cost=23.78..23.79 rows=1 width=32) |
| -> Hash Right Join (cost=8.89..23.68 rows=10 width=15) |
| 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.65 rows=565 width=14) |
| -> Hash (cost=8.87..8.87 rows=2 width=9) |
| -> Hash Join (cost=3.43..8.87 rows=2 width=9) |
| Hash Cond: (t_10.project_id = pd_3.project_id) |
| -> Hash Join (cost=1.11..6.53 rows=2 width=12) |
| Hash Cond: (t_10.project_id = t_11.project_id) |
| -> Seq Scan on tbl_erp_sales_gifts t_10 (cost=0.00..5.26 rows=54 width=8) |
| 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=1.09..1.09 rows=2 width=4) |
| -> Group (cost=1.06..1.07 rows=2 width=4) |
| Group Key: t_11.project_id |
| -> Sort (cost=1.06..1.06 rows=2 width=4) |
| Sort Key: t_11.project_id |
| -> Seq Scan on tbl_erp_profit_distributes t_11 (cost=0.00..1.05 rows=2 width=4) |
| Filter: ((project_id IS NOT NULL) AND (status = 2)) |
| -> Hash (cost=2.21..2.21 rows=8 width=9) |
| -> Hash Join (cost=1.09..2.21 rows=8 width=9) |
| Hash Cond: (am_6.erp_profit_distribute_id = pd_3.id) |
| -> Seq Scan on tbl_erp_profit_distribute_pcts am_6 (cost=0.00..1.08 rows=8 width=9) |
| -> Hash (cost=1.04..1.04 rows=4 width=8) |
| -> Seq Scan on tbl_erp_profit_distributes pd_3 (cost=0.00..1.04 rows=4 width=8) |