QUERY PLAN
Limit (cost=10484.61..10484.66 rows=19 width=202)
-> Sort (cost=10484.61..10484.66 rows=19 width=202)
Sort Key: b.bill_date DESC, b.object_type, b.object_id DESC, b.event_type, b.event_id DESC
-> Hash Left Join (cost=5.54..10484.21 rows=19 width=202)
Hash Cond: ((b.object_type = g.object_type) AND (b.object_id = g.object_id) AND (b.event_type = g.event_type) AND (b.event_id = g.event_id))
Filter: ((g.success_count IS NULL) OR (g.success_count = 0))
-> Subquery Scan on b (cost=0.28..10474.35 rows=428 width=154)
Filter: ((b.object_type <> ALL ('{20,20018}'::integer[])) OR b.have_invoice OR (SubPlan 1))
-> Append (cost=0.28..1618.92 rows=429 width=154)
-> Result (cost=0.28..790.02 rows=143 width=154)
-> Append (cost=0.28..788.23 rows=143 width=154)
-> Nested Loop Left Join (cost=0.28..110.82 rows=6 width=117)
-> Seq Scan on tbl_sales_contract_invoices i (cost=0.00..65.04 rows=6 width=43)
Filter: ((NOT is_cancel) AND (NOT is_draft) AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)) AND (from_date >= '2026-02-01'::date) AND (from_date <= '2026-06-30'::date) AND (amount > '0'::numeric))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c (cost=0.28..7.63 rows=1 width=8)
Index Cond: (id = i.contract_id)
-> Nested Loop Left Join (cost=0.28..73.34 rows=1 width=117)
-> Seq Scan on tbl_sales_contract_invoices i_1 (cost=0.00..65.04 rows=1 width=43)
Filter: ((NOT is_cancel) AND (NOT is_draft) AND (from_date >= '2026-02-01'::date) AND (from_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (invoice_type = '-1'::integer))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c_1 (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = i_1.contract_id)
-> Seq Scan on tbl_purchase_contract_invoices i_2 (cost=0.00..86.50 rows=3 width=117)
Filter: ((NOT is_cancel) AND is_verify AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)) AND (COALESCE(verify_at, from_date) >= '2026-02-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-06-30'::date) AND (amount > '0'::numeric))
-> Seq Scan on tbl_purchase_contract_invoices i_3 (cost=0.00..86.50 rows=1 width=117)
Filter: ((NOT is_cancel) AND is_verify AND (COALESCE(verify_at, from_date) >= '2026-02-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (invoice_type = '-1'::integer))
-> Subquery Scan on "*SELECT* 5" (cost=133.76..133.80 rows=1 width=154)
-> GroupAggregate (cost=133.76..133.79 rows=1 width=144)
Group Key: c_2.id
Filter: (round((COALESCE(NULLIF(sum(p.total_amount), '0'::numeric), c_2.amount, '0'::numeric) * 1.13), 2) > '0'::numeric)
-> Sort (cost=133.76..133.76 rows=1 width=47)
Sort Key: c_2.id
-> Hash Right Join (cost=76.99..133.75 rows=1 width=47)
Hash Cond: (p.project_id = c_2.from_project)
-> Seq Scan on tbl_project_product_rels p (cost=0.00..48.36 rows=2236 width=9)
-> Hash (cost=76.98..76.98 rows=1 width=46)
-> Seq Scan on tbl_sales_contracts c_2 (cost=0.00..76.98 rows=1 width=46)
Filter: ((NOT COALESCE(including_tax, false)) AND (from_project IS NOT NULL) AND (NOT COALESCE(is_draft, false)) AND (NOT COALESCE(is_verify, false)) AND (NOT COALESCE(is_edit_verify, false)) AND (NOT COALESCE(is_chargeback_verify, false)) AND (signed_at >= '2026-02-01'::date) AND (signed_at <= '2026-06-30'::date))
-> Subquery Scan on "*SELECT* 6" (cost=103.10..103.14 rows=1 width=154)
-> GroupAggregate (cost=103.10..103.13 rows=1 width=143)
Group Key: c_3.id
Filter: (round((COALESCE(NULLIF(sum(p_1.total_amount), '0'::numeric), c_3.amount, '0'::numeric) * 1.13), 2) > '0'::numeric)
-> Sort (cost=103.10..103.10 rows=1 width=47)
Sort Key: c_3.id
-> Hash Right Join (cost=93.53..103.09 rows=1 width=47)
Hash Cond: (p_1.purchase_contract_id = c_3.id)
-> Seq Scan on tbl_purchase_contract_product_rels p_1 (cost=0.00..8.40 rows=440 width=10)
-> Hash (cost=93.52..93.52 rows=1 width=41)
-> Seq Scan on tbl_purchase_contracts c_3 (cost=0.00..93.52 rows=1 width=41)
Filter: ((NOT COALESCE(including_tax, false)) AND (NOT COALESCE(is_draft, false)) AND (NOT COALESCE(is_chargeback, false)) AND (NOT COALESCE(is_verify, false)) AND (NOT COALESCE(is_edit_verify, false)) AND (NOT COALESCE(is_chargeback_verify, false)) AND (signed_at >= '2026-02-01'::date) AND (signed_at <= '2026-06-30'::date) AND (COALESCE((cost_type)::integer, 1) = 1))
-> Subquery Scan on "*SELECT* 7" (cost=21.81..22.47 rows=24 width=154)
-> HashAggregate (cost=21.81..22.23 rows=24 width=149)
Group Key: e.id
Filter: (CASE WHEN (COALESCE(e.amount, '0'::numeric) > '0'::numeric) THEN COALESCE(e.amount, '0'::numeric) ELSE COALESCE(sum(s.actual_total_amount), '0'::numeric) END > '0'::numeric)
-> Hash Right Join (cost=7.00..21.15 rows=88 width=52)
Hash Cond: (s.erp_sales_outbound_id = e.id)
-> Seq Scan on tbl_erp_inventory_product_spents s (cost=0.00..12.65 rows=565 width=9)
-> Hash (cost=6.70..6.70 rows=24 width=47)
-> Seq Scan on tbl_erp_sales_outbounds e (cost=0.00..6.70 rows=24 width=47)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 8" (cost=0.00..1.15 rows=3 width=128)
-> Seq Scan on tbl_erp_sales_returns e_1 (cost=0.00..1.12 rows=3 width=117)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 9" (cost=2.25..2.33 rows=3 width=154)
-> HashAggregate (cost=2.25..2.30 rows=3 width=147)
Group Key: e_2.id
Filter: (COALESCE(NULLIF(sum(p_2.total_amount), '0'::numeric), e_2.amount, '0'::numeric) > '0'::numeric)
-> Hash Right Join (cost=1.14..2.23 rows=3 width=50)
Hash Cond: (p_2.erp_purchase_return_id = e_2.id)
-> Seq Scan on tbl_erp_purchase_return_products p_2 (cost=0.00..1.06 rows=6 width=9)
-> Hash (cost=1.10..1.10 rows=3 width=45)
-> Seq Scan on tbl_erp_purchase_returns e_2 (cost=0.00..1.10 rows=3 width=45)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 10" (cost=0.00..80.27 rows=35 width=128)
-> Seq Scan on tbl_erp_collect_tickets e_3 (cost=0.00..79.92 rows=35 width=115)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 11" (cost=0.00..86.72 rows=64 width=128)
-> Seq Scan on tbl_erp_payment_tickets e_4 (cost=0.00..86.08 rows=64 width=114)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 12" (cost=0.00..1.07 rows=1 width=127)
-> Seq Scan on tbl_erp_advance_payment_tickets e_5 (cost=0.00..1.06 rows=1 width=115)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Result (cost=2.04..9.11 rows=13 width=154)
-> Append (cost=2.04..8.98 rows=13 width=204)
-> Hash Join (cost=2.04..4.95 rows=12 width=116)
Hash Cond: (t.id = e_6.erp_other_collect_ticket_id)
-> Seq Scan on tbl_erp_other_collect_tickets t (cost=0.00..2.59 rows=44 width=45)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.88..1.88 rows=13 width=25)
-> Seq Scan on tbl_erp_other_collect_ticket_bank_outs e_6 (cost=0.00..1.88 rows=13 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Hash Join (cost=1.03..3.90 rows=1 width=116)
Hash Cond: (t_1.id = p_3.erp_other_collect_ticket_id)
-> Seq Scan on tbl_erp_other_collect_tickets t_1 (cost=0.00..2.82 rows=11 width=53)
Filter: ((bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])) AND (bank_settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (bank_settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone))
-> Hash (cost=1.01..1.01 rows=1 width=13)
-> Seq Scan on tbl_erp_other_collect_ticket_payments p_3 (cost=0.00..1.01 rows=1 width=13)
Filter: ((amount > '0'::numeric) AND (amount > '0'::numeric))
-> Result (cost=1.38..150.51 rows=11 width=154)
-> Append (cost=1.38..150.40 rows=11 width=204)
-> Hash Join (cost=1.38..4.17 rows=5 width=116)
Hash Cond: (t_2.id = e_7.erp_other_payment_ticket_id)
-> Seq Scan on tbl_erp_other_payment_tickets t_2 (cost=0.00..2.56 rows=44 width=45)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.32..1.32 rows=5 width=25)
-> Seq Scan on tbl_erp_other_payment_ticket_bank_ins e_7 (cost=0.00..1.32 rows=5 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> GroupAggregate (cost=145.93..146.11 rows=6 width=117)
Group Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Sort (cost=145.93..145.95 rows=6 width=67)
Sort Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Nested Loop (cost=138.18..145.86 rows=6 width=67)
-> Hash Right Join (cost=138.04..144.87 rows=6 width=26)
Hash Cond: (bo.erp_payment_ticket_id = p_4.id)
-> Seq Scan on tbl_erp_payment_ticket_bank_outs bo (cost=0.00..5.78 rows=278 width=8)
-> Hash (cost=137.96..137.96 rows=6 width=26)
-> Hash Join (cost=80.27..137.96 rows=6 width=26)
Hash Cond: (s_1.erp_payment_ticket_id = p_4.id)
-> Seq Scan on tbl_erp_payment_ticket_settles s_1 (cost=0.00..51.48 rows=2364 width=18)
Filter: ((amount > '0'::numeric) AND (amount > '0'::numeric))
-> Hash (cost=80.20..80.20 rows=6 width=12)
-> Seq Scan on tbl_erp_payment_tickets p_4 (cost=0.00..80.20 rows=6 width=12)
Filter: (is_payment_settle AND (bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])) AND (bank_settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (bank_settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone))
-> Index Scan using tbl_erp_other_payment_tickets_pkey on tbl_erp_other_payment_tickets t_3 (cost=0.14..0.16 rows=1 width=45)
Index Cond: (id = s_1.erp_other_payment_ticket_id)
-> Subquery Scan on "*SELECT* 17" (cost=12.77..13.00 rows=5 width=128)
-> GroupAggregate (cost=12.77..12.95 rows=5 width=125)
Group Key: t_4.id, e_8.id
-> Sort (cost=12.77..12.78 rows=5 width=79)
Sort Key: t_4.id, e_8.id
-> Hash Right Join (cost=4.68..12.71 rows=5 width=79)
Hash Cond: (u.id = h.user_id)
-> Seq Scan on tbl_users u (cost=0.00..7.44 rows=144 width=8)
-> Hash (cost=4.62..4.62 rows=5 width=75)
-> Hash Right Join (cost=3.41..4.62 rows=5 width=75)
Hash Cond: (h.erp_other_income_ticket_id = t_4.id)
-> Seq Scan on tbl_erp_other_income_ticket_handlers h (cost=0.00..1.14 rows=14 width=8)
-> Hash (cost=3.34..3.34 rows=5 width=71)
-> Hash Join (cost=1.79..3.34 rows=5 width=71)
Hash Cond: (e_8.erp_other_income_ticket_id = t_4.id)
-> Seq Scan on tbl_erp_other_income_ticket_bank_ins e_8 (cost=0.00..1.46 rows=31 width=26)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (amount > '0'::numeric))
-> Hash (cost=1.70..1.70 rows=7 width=49)
-> Seq Scan on tbl_erp_other_income_tickets t_4 (cost=0.00..1.70 rows=7 width=49)
Filter: ((verify_at IS NOT NULL) AND (verify_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (verify_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Subquery Scan on "*SELECT* 18" (cost=0.00..3.29 rows=9 width=127)
-> Seq Scan on tbl_erp_cost_tickets e_9 (cost=0.00..3.18 rows=9 width=114)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 19" (cost=0.00..535.11 rows=49 width=127)
-> Seq Scan on tbl_erp_cash_cost_tickets e_10 (cost=0.00..534.50 rows=49 width=116)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 20" (cost=21.48..22.75 rows=46 width=154)
-> HashAggregate (cost=21.48..22.17 rows=46 width=141)
Group Key: e_11.id
Filter: (COALESCE(sum(s_2.actual_total_amount), '0'::numeric) > '0'::numeric)
-> Hash Right Join (cost=5.83..19.98 rows=201 width=44)
Hash Cond: (s_2.erp_sales_gift_id = e_11.id)
-> Seq Scan on tbl_erp_inventory_product_spents s_2 (cost=0.00..12.65 rows=565 width=9)
-> Hash (cost=5.26..5.26 rows=46 width=39)
-> Seq Scan on tbl_erp_sales_gifts e_11 (cost=0.00..5.26 rows=46 width=39)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 21" (cost=0.00..1.22 rows=3 width=128)
-> Seq Scan on tbl_erp_inventory_losts e_12 (cost=0.00..1.18 rows=3 width=115)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 22" (cost=0.00..1.26 rows=5 width=127)
-> Seq Scan on tbl_erp_inventory_overflows e_13 (cost=0.00..1.20 rows=5 width=114)
Filter: ((wrote_date >= '2026-02-01'::date) AND (wrote_date <= '2026-06-30'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 23" (cost=28.84..34.52 rows=104 width=130)
-> GroupAggregate (cost=28.84..33.48 rows=104 width=117)
Group Key: t_5.id, e_14.id
-> Sort (cost=28.84..29.24 rows=161 width=55)
Sort Key: t_5.id, e_14.id
-> Hash Left Join (cost=12.15..22.94 rows=161 width=55)
Hash Cond: (a.user_id = u_1.id)
-> Hash Right Join (cost=2.91..13.26 rows=161 width=51)
Hash Cond: (a.erp_wage_ticket_id = t_5.id)
-> Seq Scan on tbl_erp_wage_ticket_amounts a (cost=0.00..7.45 rows=345 width=8)
-> Hash (cost=2.82..2.82 rows=7 width=47)
-> Hash Join (cost=1.35..2.82 rows=7 width=47)
Hash Cond: (e_14.erp_wage_ticket_id = t_5.id)
-> Seq Scan on tbl_erp_wage_ticket_bank_outs e_14 (cost=0.00..1.44 rows=8 width=28)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Hash (cost=1.19..1.19 rows=13 width=23)
-> Seq Scan on tbl_erp_wage_tickets t_5 (cost=0.00..1.19 rows=13 width=23)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=7.44..7.44 rows=144 width=8)
-> Seq Scan on tbl_users u_1 (cost=0.00..7.44 rows=144 width=8)
-> Subquery Scan on "*SELECT* 24" (cost=16.02..16.71 rows=11 width=130)
-> GroupAggregate (cost=16.02..16.60 rows=11 width=117)
Group Key: t_6.id, e_15.id
-> Sort (cost=16.02..16.08 rows=22 width=55)
Sort Key: t_6.id, e_15.id
-> Nested Loop Left Join (cost=2.57..15.53 rows=22 width=55)
-> Hash Right Join (cost=2.43..9.32 rows=22 width=51)
Hash Cond: (a_1.erp_social_insurance_id = t_6.id)
-> Seq Scan on tbl_erp_social_insurance_amounts a_1 (cost=0.00..5.67 rows=267 width=8)
-> Hash (cost=2.41..2.41 rows=1 width=47)
-> Hash Join (cost=1.21..2.41 rows=1 width=47)
Hash Cond: (t_6.id = e_15.erp_social_insurance_id)
-> Seq Scan on tbl_erp_social_insurances t_6 (cost=0.00..1.15 rows=11 width=23)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.20..1.20 rows=1 width=28)
-> Seq Scan on tbl_erp_social_insurance_bank_outs e_15 (cost=0.00..1.20 rows=1 width=28)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Index Scan using tbl_users_pkey on tbl_users u_2 (cost=0.14..0.28 rows=1 width=8)
Index Cond: (id = a_1.user_id)
-> Subquery Scan on "*SELECT* 25" (cost=13.89..14.74 rows=19 width=128)
-> GroupAggregate (cost=13.89..14.55 rows=19 width=115)
Group Key: t_7.id, e_16.id
-> Sort (cost=13.89..13.93 rows=19 width=53)
Sort Key: t_7.id, e_16.id
-> Hash Right Join (cost=5.13..13.48 rows=19 width=53)
Hash Cond: (u_3.id = a_2.user_id)
-> Seq Scan on tbl_users u_3 (cost=0.00..7.44 rows=144 width=8)
-> Hash (cost=4.89..4.89 rows=19 width=49)
-> Hash Right Join (cost=2.41..4.89 rows=19 width=49)
Hash Cond: (a_2.erp_personal_tax_id = t_7.id)
-> Seq Scan on tbl_erp_personal_tax_amounts a_2 (cost=0.00..1.94 rows=94 width=8)
-> Hash (cost=2.39..2.39 rows=2 width=45)
-> Hash Join (cost=1.20..2.39 rows=2 width=45)
Hash Cond: (t_7.id = e_16.erp_personal_tax_id)
-> Seq Scan on tbl_erp_personal_taxs t_7 (cost=0.00..1.12 rows=10 width=23)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.18..1.18 rows=2 width=26)
-> Seq Scan on tbl_erp_personal_tax_bank_outs e_16 (cost=0.00..1.18 rows=2 width=26)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Subquery Scan on "*SELECT* 26" (cost=10.75..10.84 rows=2 width=129)
-> GroupAggregate (cost=10.75..10.82 rows=2 width=116)
Group Key: t_8.id, e_17.id
-> Sort (cost=10.75..10.76 rows=2 width=54)
Sort Key: t_8.id, e_17.id
-> Nested Loop Left Join (cost=2.38..10.74 rows=2 width=54)
-> Hash Right Join (cost=2.24..3.37 rows=2 width=50)
Hash Cond: (a_3.erp_wage_prize_id = t_8.id)
-> Seq Scan on tbl_erp_wage_prize_amounts a_3 (cost=0.00..1.08 rows=8 width=8)
-> Hash (cost=2.23..2.23 rows=1 width=46)
-> Nested Loop (cost=0.00..2.23 rows=1 width=46)
Join Filter: (t_8.id = e_17.erp_wage_prize_id)
-> Seq Scan on tbl_erp_wage_prize_bank_outs e_17 (cost=0.00..1.10 rows=1 width=27)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Seq Scan on tbl_erp_wage_prizes t_8 (cost=0.00..1.06 rows=5 width=23)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Index Scan using tbl_users_pkey on tbl_users u_4 (cost=0.14..3.66 rows=1 width=8)
Index Cond: (id = a_3.user_id)
-> Subquery Scan on "*SELECT* 27" (cost=15.20..15.85 rows=9 width=129)
-> GroupAggregate (cost=15.20..15.76 rows=9 width=117)
Group Key: t_9.id, e_18.id
-> Sort (cost=15.20..15.26 rows=23 width=55)
Sort Key: t_9.id, e_18.id
-> Nested Loop Left Join (cost=2.47..14.68 rows=23 width=55)
-> Hash Right Join (cost=2.32..7.45 rows=23 width=51)
Hash Cond: (a_4.erp_provident_fund_id = t_9.id)
-> Seq Scan on tbl_erp_provident_fund_amounts a_4 (cost=0.00..4.11 rows=211 width=8)
-> Hash (cost=2.31..2.31 rows=1 width=47)
-> Hash Join (cost=1.15..2.31 rows=1 width=47)
Hash Cond: (t_9.id = e_18.erp_provident_fund_id)
-> Seq Scan on tbl_erp_provident_funds t_9 (cost=0.00..1.11 rows=9 width=24)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=1.14..1.14 rows=1 width=27)
-> Seq Scan on tbl_erp_provident_fund_bank_outs e_18 (cost=0.00..1.14 rows=1 width=27)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-02-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Index Scan using tbl_users_pkey on tbl_users u_5 (cost=0.14..0.31 rows=1 width=8)
Index Cond: (id = a_4.user_id)
SubPlan 1
-> Nested Loop (cost=0.29..20.63 rows=1 width=0)
Join Filter: (r.taxonomy_id = tt.id)
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships r (cost=0.29..11.58 rows=1 width=4)
Index Cond: ((object_id = b.object_id) AND (term_id = 18))
Filter: (((b.object_type = 20) AND (object_type = 7)) OR ((b.object_type = 20018) AND (object_type = 11)))
-> Seq Scan on tbl_term_taxonomies tt (cost=0.00..8.99 rows=5 width=4)
Filter: ((serial_no)::text = ANY ('{221106,640301,640302,640303,600704}'::text[]))
-> Hash (cost=4.75..4.75 rows=26 width=36)
-> Subquery Scan on g (cost=4.16..4.75 rows=26 width=36)
-> HashAggregate (cost=4.16..4.49 rows=26 width=36)
Group Key: v.object_type, v.object_id, COALESCE((v.event_type)::integer, 0), COALESCE(v.event_id, 0)
-> Seq Scan on tbl_voucher_gen_items v (cost=0.00..2.81 rows=54 width=22)
Filter: (ledger_id = 1)