QUERY PLAN
Aggregate (cost=89.30..89.31 rows=1 width=32)
-> Append (cost=37.52..89.29 rows=4 width=32)
-> Subquery Scan on "*SELECT* 1" (cost=37.52..37.67 rows=3 width=32)
-> GroupAggregate (cost=37.52..37.64 rows=3 width=421)
Group Key: r.id
-> Sort (cost=37.52..37.55 rows=11 width=8)
Sort Key: r.id
-> Hash Right Join (cost=23.35..37.33 rows=11 width=8)
Hash Cond: (eipss.erp_sales_outbound_id = r.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=551 width=8)
-> Hash (cost=23.31..23.31 rows=3 width=4)
-> Seq Scan on tbl_erp_sales_outbounds r (cost=12.89..23.31 rows=3 width=4)
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 1)) OR (project_id IS NULL)) AND (status = 2) AND (handler = 1001))
SubPlan 1
-> 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* 2" (cost=51.58..51.62 rows=1 width=32)
-> GroupAggregate (cost=51.58..51.61 rows=1 width=430)
Group Key: r_1.id, am.user_id, am.pct
-> Sort (cost=51.58..51.58 rows=1 width=17)
Sort Key: r_1.id, am.pct
-> Nested Loop (cost=35.95..51.57 rows=1 width=17)
Join Filter: (pd.id = am.erp_profit_distribute_id)
-> Hash Join (cost=35.95..50.43 rows=1 width=12)
Hash Cond: (r_1.project_id = pd.project_id)
-> Hash Right Join (cost=10.11..24.09 rows=130 width=12)
Hash Cond: (eipss_1.erp_sales_outbound_id = r_1.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.51 rows=551 width=8)
-> Hash (cost=9.66..9.66 rows=36 width=8)
-> Seq Scan on tbl_erp_sales_outbounds r_1 (cost=0.00..9.66 rows=36 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=25.83..25.83 rows=1 width=12)
-> Hash Join (cost=12.91..25.83 rows=1 width=12)
Hash Cond: (pd.project_id = t.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.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))
-> Seq Scan on tbl_erp_profit_distribute_pcts am (cost=0.00..1.10 rows=3 width=13)
Filter: (user_id = 1001)