QUERY PLAN
Sort (cost=75196.21..75196.57 rows=144 width=241)
Sort Key: (((((((COALESCE(sum((sum((sum(eipss.total_amount))))), '0'::numeric) + COALESCE(sum(t.budget), '0'::numeric)) + COALESCE(sum(sub_other_in.amount), '0'::numeric)) - COALESCE(sum((sum((sum(eipss.actual_total_amount))))), '0'::numeric)) - COALESCE(sum(t.cost), '0'::numeric)) - COALESCE(sum(sub_out.amount), '0'::numeric)) - COALESCE(sum(t.expense), '0'::numeric))) DESC, u.id
-> Hash Full Join (cost=3836.68..75191.05 rows=144 width=241)
Hash Cond: (u_1.id = u.id)
Filter: ((u.user_status = '1'::type_global_user_status) OR (((COALESCE(sum((sum((sum(eipss.total_amount))))), '0'::numeric) + COALESCE(sum(t.budget), '0'::numeric))) <> '0'::numeric) OR (((COALESCE(sum((sum((sum(eipss.actual_total_amount))))), '0'::numeric) + COALESCE(sum(t.cost), '0'::numeric))) <> '0'::numeric) OR ((COALESCE(sum(sub_other_in.amount), '0'::numeric)) <> '0'::numeric) OR (((COALESCE(sum(sub_out.amount), '0'::numeric) + COALESCE(sum(t.expense), '0'::numeric))) <> '0'::numeric) OR (((((((COALESCE(sum((sum((sum(eipss.actual_total_amount))))), '0'::numeric) + COALESCE(sum(t.cost), '0'::numeric)) + COALESCE(sum(sub_out.amount), '0'::numeric)) + COALESCE(sum(t.expense), '0'::numeric)))::double precision + COALESCE(sum((COALESCE(sum(CASE WHEN ("*SELECT* 1".work_hours > '0'::double precision) THEN ((((COALESCE(payroll.amount, '0'::numeric) / (GREATEST((SubPlan 10), '1'::bigint))::numeric))::double precision / GREATEST(CASE WHEN (ps.id IS NULL) THEN '8'::double precision WHEN (ps.punch_type = 0) THEN '8'::double precision WHEN ((ps.work_hour IS NOT NULL) AND (ps.work_hour > '0'::double precision)) THEN ps.work_hour ELSE '8'::double precision END, '1'::double precision)) * "*SELECT* 1".work_hours) ELSE '0'::double precision END), '0'::double precision))), '0'::double precision))) <> '0'::double precision) OR ((((COALESCE(sum((sum((sum(eipss.total_amount))))), '0'::numeric) + COALESCE(sum(t.budget), '0'::numeric)) + COALESCE(sum(sub_other_in.amount), '0'::numeric))) <> '0'::numeric) OR ((((((((COALESCE(sum((sum((sum(eipss.total_amount))))), '0'::numeric) + COALESCE(sum(t.budget), '0'::numeric)) + COALESCE(sum(sub_other_in.amount), '0'::numeric)) - COALESCE(sum((sum((sum(eipss.actual_total_amount))))), '0'::numeric)) - COALESCE(sum(t.cost), '0'::numeric)) - COALESCE(sum(sub_out.amount), '0'::numeric)) - COALESCE(sum(t.expense), '0'::numeric))) <> '0'::numeric) OR ((COALESCE(sum((COALESCE(sum(CASE WHEN ("*SELECT* 1".work_hours > '0'::double precision) THEN ((((COALESCE(payroll.amount, '0'::numeric) / (GREATEST((SubPlan 10), '1'::bigint))::numeric))::double precision / GREATEST(CASE WHEN (ps.id IS NULL) THEN '8'::double precision WHEN (ps.punch_type = 0) THEN '8'::double precision WHEN ((ps.work_hour IS NOT NULL) AND (ps.work_hour > '0'::double precision)) THEN ps.work_hour ELSE '8'::double precision END, '1'::double precision)) * "*SELECT* 1".work_hours) ELSE '0'::double precision END), '0'::double precision))), '0'::double precision)) <> '0'::double precision) OR ((((((((((COALESCE(sum((sum((sum(eipss.total_amount))))), '0'::numeric) + COALESCE(sum(t.budget), '0'::numeric)) + COALESCE(sum(sub_other_in.amount), '0'::numeric)) - COALESCE(sum((sum((sum(eipss.actual_total_amount))))), '0'::numeric)) - COALESCE(sum(t.cost), '0'::numeric)) - COALESCE(sum(sub_out.amount), '0'::numeric)) - COALESCE(sum(t.expense), '0'::numeric)))::double precision - COALESCE(sum((COALESCE(sum(CASE WHEN ("*SELECT* 1".work_hours > '0'::double precision) THEN ((((COALESCE(payroll.amount, '0'::numeric) / (GREATEST((SubPlan 10), '1'::bigint))::numeric))::double precision / GREATEST(CASE WHEN (ps.id IS NULL) THEN '8'::double precision WHEN (ps.punch_type = 0) THEN '8'::double precision WHEN ((ps.work_hour IS NOT NULL) AND (ps.work_hour > '0'::double precision)) THEN ps.work_hour ELSE '8'::double precision END, '1'::double precision)) * "*SELECT* 1".work_hours) ELSE '0'::double precision END), '0'::double precision))), '0'::double precision))) <> '0'::double precision))
-> GroupAggregate (cost=3818.44..75170.96 rows=144 width=220)
Group Key: u_1.id
-> Merge Left Join (cost=3818.44..75139.28 rows=144 width=236)
Merge Cond: (u_1.id = "*SELECT* 1".engineer_id)
-> Sort (cost=2694.32..2694.68 rows=144 width=228)
Sort Key: u_1.id
-> Hash Full Join (cost=2676.70..2689.15 rows=144 width=228)
Hash Cond: (u_1.id = t.user_id)
-> Hash Full Join (cost=2675.07..2686.70 rows=144 width=132)
Hash Cond: (u_1.id = sub_out.user_id)
-> Hash Full Join (cost=367.63..378.87 rows=144 width=100)
Hash Cond: (u_1.id = sub_other_in.user_id)
-> Merge Full Join (cost=90.86..101.71 rows=144 width=68)
Merge Cond: (u_1.id = t_1.handler)
-> Index Only Scan using tbl_users_pkey on tbl_users u_1 (cost=0.14..10.30 rows=144 width=4)
-> GroupAggregate (cost=90.72..90.89 rows=7 width=68)
Group Key: t_1.handler
-> Sort (cost=90.72..90.73 rows=7 width=68)
Sort Key: t_1.handler
-> Append (cost=38.97..90.62 rows=7 width=68)
-> HashAggregate (cost=38.97..39.06 rows=6 width=68)
Group Key: t_1.handler
-> Hash Right Join (cost=23.06..37.04 rows=257 width=13)
Hash Cond: (eipss.erp_sales_outbound_id = t_1.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=551 width=13)
-> Hash (cost=22.17..22.17 rows=71 width=8)
-> Seq Scan on tbl_erp_sales_outbounds t_1 (cost=12.89..22.17 rows=71 width=8)
Filter: (((NOT (hashed SubPlan 1)) OR (project_id IS NULL)) AND (status = 2))
SubPlan 1
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_29.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_29.project_id
-> Seq Scan on tbl_erp_profit_distributes t_29 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> GroupAggregate (cost=51.45..51.49 rows=1 width=68)
Group Key: am.user_id
-> Sort (cost=51.45..51.46 rows=1 width=18)
Sort Key: am.user_id
-> Nested Loop (cost=35.40..51.44 rows=1 width=18)
Join Filter: (pd.id = am.erp_profit_distribute_id)
-> Seq Scan on tbl_erp_profit_distribute_pcts am (cost=0.00..1.08 rows=8 width=13)
-> Materialize (cost=35.40..50.01 rows=3 width=13)
-> Hash Right Join (cost=35.40..50.00 rows=3 width=13)
Hash Cond: (eipss_1.erp_sales_outbound_id = t_2.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.51 rows=551 width=13)
-> Hash (cost=35.39..35.39 rows=1 width=8)
-> Hash Join (cost=22.21..35.39 rows=1 width=8)
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=22.20..22.20 rows=1 width=12)
-> Hash Join (cost=12.91..22.20 rows=1 width=12)
Hash Cond: (t_2.project_id = t_3.project_id)
-> Seq Scan on tbl_erp_sales_outbounds t_2 (cost=0.00..8.90 rows=143 width=8)
Filter: (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))
-> Hash (cost=276.60..276.60 rows=13 width=36)
-> Subquery Scan on sub_other_in (cost=275.75..276.60 rows=13 width=36)
-> GroupAggregate (cost=275.75..276.47 rows=13 width=36)
Group Key: am_1.user_id
-> Merge Append (cost=275.75..276.25 rows=13 width=36)
Sort Key: am_1.user_id
-> GroupAggregate (cost=122.70..122.94 rows=12 width=36)
Group Key: am_1.user_id
-> Sort (cost=122.70..122.73 rows=12 width=36)
Sort Key: am_1.user_id
-> Append (cost=58.32..122.48 rows=12 width=36)
-> GroupAggregate (cost=58.32..58.48 rows=8 width=36)
Group Key: am_1.user_id
-> Sort (cost=58.32..58.34 rows=8 width=36)
Sort Key: am_1.user_id
-> Nested Loop Left Join (cost=14.38..58.20 rows=8 width=36)
Filter: ((NOT (hashed SubPlan 2)) OR (t_4.sales_contract_id IS NULL))
-> Hash Join (cost=1.20..3.92 rows=8 width=40)
Hash Cond: (t_4.id = am_1.erp_other_income_ticket_id)
-> Seq Scan on tbl_erp_other_income_tickets t_4 (cost=0.00..2.50 rows=37 width=8)
Filter: (status = 2)
-> Hash (cost=1.09..1.09 rows=9 width=40)
-> Seq Scan on tbl_erp_other_income_ticket_handlers am_1 (cost=0.00..1.09 rows=9 width=40)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc (cost=0.28..5.16 rows=1 width=8)
Index Cond: (id = t_4.sales_contract_id)
SubPlan 2
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_30.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_30.project_id
-> Seq Scan on tbl_erp_profit_distributes t_30 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Aggregate (cost=21.99..22.00 rows=1 width=36)
-> Nested Loop Left Join (cost=14.38..21.99 rows=1 width=6)
Filter: ((NOT (hashed SubPlan 3)) OR (t_5.sales_contract_id IS NULL))
-> Hash Left Join (cost=1.20..3.92 rows=1 width=10)
Hash Cond: (t_5.id = am_2.erp_other_income_ticket_id)
Filter: (am_2.user_id IS NULL)
-> Seq Scan on tbl_erp_other_income_tickets t_5 (cost=0.00..2.50 rows=37 width=14)
Filter: (status = 2)
-> Hash (cost=1.09..1.09 rows=9 width=8)
-> Seq Scan on tbl_erp_other_income_ticket_handlers am_2 (cost=0.00..1.09 rows=9 width=8)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_1 (cost=0.28..5.16 rows=1 width=8)
Index Cond: (id = t_5.sales_contract_id)
SubPlan 3
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_31.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_31.project_id
-> Seq Scan on tbl_erp_profit_distributes t_31 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> HashAggregate (cost=1.12..1.15 rows=2 width=36)
Group Key: t_6.handler
-> Seq Scan on tbl_erp_inventory_overflows t_6 (cost=0.00..1.10 rows=4 width=9)
Filter: (status = 2)
-> Aggregate (cost=40.73..40.74 rows=1 width=36)
-> Nested Loop Anti Join (cost=33.12..40.73 rows=1 width=5)
Join Filter: (t_8.erp_inventory_overflow_id = t_7.id)
-> Seq Scan on tbl_erp_inventory_overflows t_7 (cost=0.00..1.10 rows=1 width=9)
Filter: ((handler IS NULL) AND (status = 2))
-> HashAggregate (cost=33.12..35.12 rows=200 width=4)
Group Key: t_8.erp_inventory_overflow_id
-> Seq Scan on tbl_erp_inventory_overflow_projects t_8 (cost=0.00..28.50 rows=1850 width=4)
Filter: ((client_id IS NOT NULL) OR (project_id IS NOT NULL))
-> GroupAggregate (cost=153.04..153.07 rows=1 width=36)
Group Key: am_3.user_id
-> Sort (cost=153.04..153.05 rows=1 width=15)
Sort Key: am_3.user_id
-> Nested Loop (cost=135.72..153.03 rows=1 width=15)
Join Filter: (sc_2.id = t_9.sales_contract_id)
-> Nested Loop (cost=135.72..150.07 rows=1 width=13)
Join Filter: (pd_1.id = am_3.erp_profit_distribute_id)
-> Hash Join (cost=135.72..148.89 rows=1 width=8)
Hash Cond: (pd_1.project_id = sc_2.from_project)
-> Seq Scan on tbl_erp_profit_distributes pd_1 (cost=0.00..12.30 rows=230 width=8)
-> Hash (cost=135.70..135.70 rows=1 width=12)
-> Hash Join (cost=12.91..135.70 rows=1 width=12)
Hash Cond: (sc_2.from_project = t_10.project_id)
-> Seq Scan on tbl_sales_contracts sc_2 (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_10.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_10.project_id
-> Seq Scan on tbl_erp_profit_distributes t_10 (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=13)
-> Seq Scan on tbl_erp_other_income_tickets t_9 (cost=0.00..2.50 rows=37 width=10)
Filter: (status = 2)
-> Hash (cost=2306.13..2306.13 rows=105 width=36)
-> Subquery Scan on sub_out (cost=2302.98..2306.13 rows=105 width=36)
-> GroupAggregate (cost=2302.98..2305.08 rows=105 width=36)
Group Key: am_4.user_id
-> Sort (cost=2302.98..2303.24 rows=105 width=36)
Sort Key: am_4.user_id
-> Append (cost=1453.64..2299.46 rows=105 width=36)
-> GroupAggregate (cost=1453.64..1454.86 rows=61 width=36)
Group Key: am_4.user_id
-> Sort (cost=1453.64..1453.80 rows=61 width=36)
Sort Key: am_4.user_id
-> Append (cost=798.70..1451.84 rows=61 width=36)
-> HashAggregate (cost=798.70..799.45 rows=60 width=36)
Group Key: am_4.user_id
-> Hash Left Join (cost=632.95..793.80 rows=980 width=9)
Hash Cond: (t_11.sales_contract_id = sc_3.id)
Filter: ((NOT (hashed SubPlan 4)) OR (t_11.sales_contract_id IS NULL))
-> Hash Join (cost=480.25..638.16 rows=1116 width=13)
Hash Cond: (am_4.erp_cash_cost_ticket_id = t_11.id)
-> Seq Scan on tbl_erp_cash_cost_ticket_handlers am_4 (cost=0.00..136.09 rows=8309 width=13)
-> Hash (cost=466.03..466.03 rows=1137 width=8)
-> Seq Scan on tbl_erp_cash_cost_tickets t_11 (cost=0.00..466.03 rows=1137 width=8)
Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=118.25..118.25 rows=1725 width=8)
-> Seq Scan on tbl_sales_contracts sc_3 (cost=0.00..118.25 rows=1725 width=8)
SubPlan 4
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_32.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_32.project_id
-> Seq Scan on tbl_erp_profit_distributes t_32 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Aggregate (cost=651.77..651.78 rows=1 width=36)
-> Nested Loop Left Join (cost=493.42..651.76 rows=1 width=5)
Filter: ((NOT (hashed SubPlan 5)) OR (t_12.sales_contract_id IS NULL))
-> Hash Right Join (cost=480.25..638.16 rows=1 width=9)
Hash Cond: (am_5.erp_cash_cost_ticket_id = t_12.id)
Filter: (am_5.user_id IS NULL)
-> Seq Scan on tbl_erp_cash_cost_ticket_handlers am_5 (cost=0.00..136.09 rows=8309 width=8)
-> Hash (cost=466.03..466.03 rows=1137 width=13)
-> Seq Scan on tbl_erp_cash_cost_tickets t_12 (cost=0.00..466.03 rows=1137 width=13)
Filter: (is_payment_settle 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_4 (cost=0.28..0.70 rows=1 width=8)
Index Cond: (id = t_12.sales_contract_id)
SubPlan 5
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_33.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_33.project_id
-> Seq Scan on tbl_erp_profit_distributes t_33 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> GroupAggregate (cost=622.00..622.02 rows=1 width=36)
Group Key: am_6.user_id
-> Sort (cost=622.00..622.00 rows=1 width=14)
Sort Key: am_6.user_id
-> Nested Loop (cost=136.90..621.99 rows=1 width=14)
Join Filter: (pd_2.project_id = sc_5.from_project)
-> Hash Join (cost=135.72..606.03 rows=1 width=13)
Hash Cond: (t_13.sales_contract_id = sc_5.id)
-> Seq Scan on tbl_erp_cash_cost_tickets t_13 (cost=0.00..466.03 rows=1137 width=9)
Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=135.70..135.70 rows=1 width=12)
-> Hash Join (cost=12.91..135.70 rows=1 width=12)
Hash Cond: (sc_5.from_project = t_14.project_id)
-> Seq Scan on tbl_sales_contracts sc_5 (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_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))
-> Hash Join (cost=1.18..15.86 rows=8 width=13)
Hash Cond: (pd_2.id = am_6.erp_profit_distribute_id)
-> Seq Scan on tbl_erp_profit_distributes pd_2 (cost=0.00..12.30 rows=230 width=8)
-> Hash (cost=1.08..1.08 rows=8 width=13)
-> Seq Scan on tbl_erp_profit_distribute_pcts am_6 (cost=0.00..1.08 rows=8 width=13)
-> HashAggregate (cost=39.70..40.07 rows=30 width=36)
Group Key: am_7.user_id
-> Append (cost=19.50..39.55 rows=30 width=36)
-> HashAggregate (cost=19.50..19.86 rows=29 width=36)
Group Key: am_7.user_id
-> Hash Join (cost=17.73..19.35 rows=29 width=36)
Hash Cond: (am_7.erp_cost_ticket_id = t_15.id)
-> Seq Scan on tbl_erp_cost_ticket_handlers am_7 (cost=0.00..1.49 rows=49 width=40)
-> Hash (cost=17.12..17.12 rows=48 width=4)
-> Seq Scan on tbl_erp_cost_tickets t_15 (cost=12.89..17.12 rows=48 width=4)
Filter: (((NOT (hashed SubPlan 6)) OR (project_id IS NULL)) AND (status = 2))
SubPlan 6
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_34.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_34.project_id
-> Seq Scan on tbl_erp_profit_distributes t_34 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Subquery Scan on "*SELECT* 2" (cost=19.36..19.40 rows=1 width=36)
-> GroupAggregate (cost=19.36..19.39 rows=1 width=40)
Group Key: am_8.user_id
-> Sort (cost=19.36..19.37 rows=1 width=9)
Sort Key: am_8.user_id
-> Hash Right Join (cost=17.73..19.35 rows=1 width=9)
Hash Cond: (am_8.erp_cost_ticket_id = t_16.id)
Filter: (am_8.user_id IS NULL)
-> Seq Scan on tbl_erp_cost_ticket_handlers am_8 (cost=0.00..1.49 rows=49 width=8)
-> Hash (cost=17.12..17.12 rows=48 width=9)
-> Seq Scan on tbl_erp_cost_tickets t_16 (cost=12.89..17.12 rows=48 width=9)
Filter: (((NOT (hashed SubPlan 7)) OR (project_id IS NULL)) AND (status = 2))
SubPlan 7
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_35.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_35.project_id
-> Seq Scan on tbl_erp_profit_distributes t_35 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> GroupAggregate (cost=31.52..31.55 rows=1 width=36)
Group Key: am_9.user_id
-> Sort (cost=31.52..31.52 rows=1 width=14)
Sort Key: am_9.user_id
-> Nested Loop (cost=17.16..31.51 rows=1 width=14)
Join Filter: (pd_3.id = am_9.erp_profit_distribute_id)
-> Hash Join (cost=17.16..30.33 rows=1 width=9)
Hash Cond: (pd_3.project_id = t_17.project_id)
-> Seq Scan on tbl_erp_profit_distributes pd_3 (cost=0.00..12.30 rows=230 width=8)
-> Hash (cost=17.14..17.14 rows=1 width=13)
-> Hash Join (cost=12.91..17.14 rows=1 width=13)
Hash Cond: (t_17.project_id = t_18.project_id)
-> Seq Scan on tbl_erp_cost_tickets t_17 (cost=0.00..4.03 rows=73 width=9)
Filter: (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_18.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_18.project_id
-> Seq Scan on tbl_erp_profit_distributes t_18 (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_9 (cost=0.00..1.08 rows=8 width=13)
-> GroupAggregate (cost=24.05..24.11 rows=3 width=36)
Group Key: am_10.user_id
-> Sort (cost=24.05..24.06 rows=3 width=36)
Sort Key: am_10.user_id
-> Hash Join (cost=22.34..24.02 rows=3 width=36)
Hash Cond: (am_10.erp_cost_convert_ticket_id = t_19.id)
-> Seq Scan on tbl_erp_cost_convert_ticket_handlers am_10 (cost=0.00..1.49 rows=49 width=40)
-> Hash (cost=22.33..22.33 rows=1 width=4)
-> Nested Loop Left Join (cost=13.17..22.33 rows=1 width=4)
Filter: ((NOT (hashed SubPlan 8)) OR (t_19.sales_contract_id IS NULL))
-> Seq Scan on tbl_erp_cost_convert_tickets t_19 (cost=0.00..1.12 rows=1 width=8)
Filter: (status = 2)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_6 (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = t_19.sales_contract_id)
SubPlan 8
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_36.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_36.project_id
-> Seq Scan on tbl_erp_profit_distributes t_36 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> GroupAggregate (cost=36.46..36.49 rows=1 width=36)
Group Key: am_11.user_id
-> Sort (cost=36.46..36.47 rows=1 width=41)
Sort Key: am_11.user_id
-> Nested Loop (cost=13.19..36.45 rows=1 width=41)
Join Filter: (pd_4.id = am_11.erp_profit_distribute_id)
-> Nested Loop (cost=13.19..35.27 rows=1 width=36)
Join Filter: (pd_4.project_id = sc_7.from_project)
-> Hash Join (cost=12.91..25.83 rows=1 width=12)
Hash Cond: (pd_4.project_id = t_21.project_id)
-> Seq Scan on tbl_erp_profit_distributes pd_4 (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_21.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_21.project_id
-> Seq Scan on tbl_erp_profit_distributes t_21 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Nested Loop (cost=0.28..9.43 rows=1 width=36)
-> Seq Scan on tbl_erp_cost_convert_tickets t_20 (cost=0.00..1.12 rows=1 width=36)
Filter: (status = 2)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts sc_7 (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = t_20.sales_contract_id)
-> Seq Scan on tbl_erp_profit_distribute_pcts am_11 (cost=0.00..1.08 rows=8 width=13)
-> HashAggregate (cost=39.41..39.50 rows=7 width=36)
Group Key: t_22.handler
-> Hash Right Join (cost=22.02..35.98 rows=457 width=13)
Hash Cond: (eipss_2.erp_sales_gift_id = t_22.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_2 (cost=0.00..12.51 rows=551 width=13)
-> Hash (cost=20.74..20.74 rows=102 width=8)
-> Seq Scan on tbl_erp_sales_gifts t_22 (cost=12.89..20.74 rows=102 width=8)
Filter: (((NOT (hashed SubPlan 9)) OR (project_id IS NULL)) AND (status = 2))
SubPlan 9
-> Group (cost=12.88..12.89 rows=1 width=4)
Group Key: t_37.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_37.project_id
-> Seq Scan on tbl_erp_profit_distributes t_37 (cost=0.00..12.88 rows=1 width=4)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> GroupAggregate (cost=49.78..49.81 rows=1 width=36)
Group Key: am_12.user_id
-> Sort (cost=49.78..49.78 rows=1 width=18)
Sort Key: am_12.user_id
-> Nested Loop (cost=34.00..49.77 rows=1 width=18)
Join Filter: (pd_5.id = am_12.erp_profit_distribute_id)
-> Hash Right Join (cost=34.00..48.59 rows=1 width=13)
Hash Cond: (eipss_3.erp_sales_gift_id = t_23.id)
-> Seq Scan on tbl_erp_inventory_product_spents eipss_3 (cost=0.00..12.51 rows=551 width=13)
-> Hash (cost=33.99..33.99 rows=1 width=8)
-> Hash Join (cost=20.81..33.99 rows=1 width=8)
Hash Cond: (pd_5.project_id = t_23.project_id)
-> Seq Scan on tbl_erp_profit_distributes pd_5 (cost=0.00..12.30 rows=230 width=8)
-> Hash (cost=20.79..20.79 rows=2 width=12)
-> Hash Join (cost=12.91..20.79 rows=2 width=12)
Hash Cond: (t_23.project_id = t_24.project_id)
-> Seq Scan on tbl_erp_sales_gifts t_23 (cost=0.00..7.54 rows=120 width=8)
Filter: (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_24.project_id
-> Sort (cost=12.88..12.89 rows=1 width=4)
Sort Key: t_24.project_id
-> Seq Scan on tbl_erp_profit_distributes t_24 (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_12 (cost=0.00..1.08 rows=8 width=13)
-> Hash (cost=1.28..1.28 rows=28 width=100)
-> Seq Scan on tbl_erp_user_profits t (cost=0.00..1.28 rows=28 width=100)
-> GroupAggregate (cost=1124.13..72440.30 rows=200 width=12)
Group Key: "*SELECT* 1".engineer_id
-> Merge Left Join (cost=1124.13..1141.82 rows=2854 width=65)
Merge Cond: ("*SELECT* 1".engineer_id = psrr.user_id)
-> Sort (cost=1121.52..1128.66 rows=2854 width=48)
Sort Key: "*SELECT* 1".engineer_id
-> Hash Left Join (cost=49.82..957.72 rows=2854 width=48)
Hash Cond: (("*SELECT* 1".engineer_id = payroll.user_id) AND ("*SELECT* 1".settle_month = payroll.settle_month))
-> Append (cost=0.00..892.92 rows=2854 width=16)
-> Subquery Scan on "*SELECT* 1" (cost=0.00..104.55 rows=541 width=16)
-> Seq Scan on tbl_pre_sales p (cost=0.00..99.14 rows=541 width=280)
Filter: ((start_at IS NOT NULL) AND (end_at IS NOT NULL) AND (engineer_id IS NOT NULL) AND ((NOT is_draft) OR (is_draft IS NULL)) AND (engineer_id IS NOT NULL) AND (end_at > start_at))
-> Subquery Scan on "*SELECT* 2_1" (cost=372.34..788.38 rows=2313 width=16)
-> Hash Join (cost=372.34..765.25 rows=2313 width=280)
Hash Cond: (i.case_id = c.id)
-> Seq Scan on tbl_implement_records i (cost=0.00..357.85 rows=2340 width=24)
Filter: ((arrived_at IS NOT NULL) AND (left_at IS NOT NULL) AND ((NOT is_draft) OR (is_draft IS NULL)) AND (left_at > arrived_at))
-> Hash (cost=267.14..267.14 rows=8416 width=12)
-> Seq Scan on tbl_cases c (cost=0.00..267.14 rows=8416 width=12)
Filter: ((last_engineer IS NOT NULL) AND (last_engineer IS NOT NULL))
-> Hash (cost=46.82..46.82 rows=200 width=40)
-> Subquery Scan on payroll (cost=42.32..46.82 rows=200 width=40)
-> HashAggregate (cost=42.32..44.82 rows=200 width=40)
Group Key: am_13.user_id, t_25.settle_month
-> Append (cost=12.96..40.31 rows=268 width=40)
-> HashAggregate (cost=12.96..15.56 rows=208 width=40)
Group Key: am_13.user_id, t_25.settle_month
-> Hash Join (cost=1.31..10.92 rows=271 width=11)
Hash Cond: (am_13.erp_wage_ticket_id = t_25.id)
-> Seq Scan on tbl_erp_wage_ticket_amounts am_13 (cost=0.00..8.45 rows=345 width=11)
Filter: (user_id IS NOT NULL)
-> Hash (cost=1.18..1.18 rows=11 width=8)
-> Seq Scan on tbl_erp_wage_tickets t_25 (cost=0.00..1.18 rows=11 width=8)
Filter: (status = 2)
-> HashAggregate (cost=9.96..10.28 rows=26 width=40)
Group Key: am_14.user_id, t_26.settle_month
-> Hash Join (cost=1.14..9.75 rows=27 width=11)
Hash Cond: (am_14.erp_social_insurance_id = t_26.id)
-> Seq Scan on tbl_erp_social_insurance_amounts am_14 (cost=0.00..7.67 rows=267 width=11)
Filter: (user_id IS NOT NULL)
-> Hash (cost=1.12..1.12 rows=1 width=8)
-> Seq Scan on tbl_erp_social_insurances t_26 (cost=0.00..1.12 rows=1 width=8)
Filter: (status = 2)
-> HashAggregate (cost=8.24..8.57 rows=26 width=40)
Group Key: am_15.user_id, t_27.settle_month
-> Hash Join (cost=1.10..8.02 rows=30 width=11)
Hash Cond: (am_15.erp_provident_fund_id = t_27.id)
-> Seq Scan on tbl_erp_provident_fund_amounts am_15 (cost=0.00..6.11 rows=211 width=11)
Filter: (user_id IS NOT NULL)
-> Hash (cost=1.09..1.09 rows=1 width=8)
-> Seq Scan on tbl_erp_provident_funds t_27 (cost=0.00..1.09 rows=1 width=8)
Filter: (status = 2)
-> HashAggregate (cost=3.12..3.22 rows=8 width=40)
Group Key: am_16.user_id, t_28.settle_month
-> Hash Join (cost=1.11..3.06 rows=8 width=14)
Hash Cond: (am_16.erp_personal_tax_id = t_28.id)
-> Seq Scan on tbl_erp_personal_tax_amounts am_16 (cost=0.00..1.68 rows=68 width=14)
Filter: (user_id IS NOT NULL)
-> Hash (cost=1.10..1.10 rows=1 width=8)
-> Seq Scan on tbl_erp_personal_taxs t_28 (cost=0.00..1.10 rows=1 width=8)
Filter: (status = 2)
-> Sort (cost=2.60..2.64 rows=16 width=21)
Sort Key: psrr.user_id
-> Hash Left Join (cost=1.07..2.28 rows=16 width=21)
Hash Cond: (psrr.punch_strategy_id = ps.id)
-> Seq Scan on tbl_punch_strategy_resource_rels psrr (cost=0.00..1.16 rows=16 width=8)
-> Hash (cost=1.03..1.03 rows=3 width=17)
-> Seq Scan on tbl_punch_strategies ps (cost=0.00..1.03 rows=3 width=17)
SubPlan 10
-> Aggregate (cost=24.94..24.95 rows=1 width=8)
-> Hash Left Join (cost=5.67..23.69 rows=500 width=0)
Hash Cond: ((work_dates.work_date)::date = pss.edate)
Filter: CASE WHEN (ps.id IS NULL) THEN (((date_part('isodow'::text, work_dates.work_date))::integer >= 1) AND ((date_part('isodow'::text, work_dates.work_date))::integer <= 5)) WHEN (pss.id IS NOT NULL) THEN pss.need_work WHEN (ps.legal_holiday AND (lh.id IS NOT NULL)) THEN lh.is_exchange ELSE (((ps.week)::integer & (1 << ((date_part('isodow'::text, work_dates.work_date))::integer - 1))) <> 0) END
-> Hash Left Join (cost=4.29..17.10 rows=1000 width=13)
Hash Cond: ((work_dates.work_date)::date = lh.edate)
-> Function Scan on generate_series work_dates (cost=0.01..10.01 rows=1000 width=8)
-> Hash (cost=2.46..2.46 rows=146 width=9)
-> Seq Scan on tbl_legal_holidays lh (cost=0.00..2.46 rows=146 width=9)
-> Hash (cost=1.36..1.36 rows=1 width=9)
-> Seq Scan on tbl_punch_strategy_schedules pss (cost=0.00..1.36 rows=1 width=9)
Filter: (punch_strategy_id = ps.id)
-> Hash (cost=16.44..16.44 rows=144 width=29)
-> Seq Scan on tbl_users u (cost=0.00..16.44 rows=144 width=29)