QUERY PLAN
Aggregate (cost=3641.30..3641.31 rows=1 width=32)
-> Hash Left Join (cost=5.00..3641.29 rows=4 width=32)
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..3635.51 rows=100 width=48)
Filter: ((b.object_type <> ALL ('{20,20018}'::integer[])) OR b.have_invoice OR (SubPlan 1))
-> Append (cost=0.28..1571.31 rows=100 width=154)
-> Result (cost=0.28..774.66 rows=30 width=154)
-> Append (cost=0.28..774.28 rows=30 width=154)
-> Nested Loop Left Join (cost=0.28..73.34 rows=1 width=117)
-> Seq Scan on tbl_sales_contract_invoices i (cost=0.00..65.04 rows=1 width=43)
Filter: ((NOT is_cancel) AND (NOT is_draft) AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)) AND (from_date >= '2026-05-01'::date) AND (from_date <= '2026-05-31'::date) AND (amount > '0'::numeric))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c (cost=0.28..8.29 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-05-01'::date) AND (from_date <= '2026-05-31'::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..99.38 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-05-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (COALESCE(verify_at, from_date) >= '2026-06-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-06-30'::date))
-> Seq Scan on tbl_purchase_contract_invoices i_3 (cost=0.00..99.38 rows=1 width=117)
Filter: ((NOT is_cancel) AND is_verify AND (COALESCE(verify_at, from_date) >= '2026-05-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (COALESCE(verify_at, from_date) >= '2026-06-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-06-30'::date) 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-05-01'::date) AND (signed_at <= '2026-05-31'::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-05-01'::date) AND (signed_at <= '2026-05-31'::date) AND (COALESCE((cost_type)::integer, 1) = 1))
-> Subquery Scan on "*SELECT* 7" (cost=21.09..21.26 rows=6 width=154)
-> HashAggregate (cost=21.09..21.20 rows=6 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=6.77..20.93 rows=22 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=6 width=47)
-> Seq Scan on tbl_erp_sales_outbounds e (cost=0.00..6.70 rows=6 width=47)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 8" (cost=0.00..1.13 rows=1 width=128)
-> Seq Scan on tbl_erp_sales_returns e_1 (cost=0.00..1.12 rows=1 width=117)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 9" (cost=2.21..2.25 rows=1 width=154)
-> GroupAggregate (cost=2.21..2.24 rows=1 width=147)
Group Key: e_2.id
Filter: (COALESCE(NULLIF(sum(p_2.total_amount), '0'::numeric), e_2.amount, '0'::numeric) > '0'::numeric)
-> Sort (cost=2.21..2.22 rows=1 width=50)
Sort Key: e_2.id
-> Hash Right Join (cost=1.12..2.20 rows=1 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=1 width=45)
-> Seq Scan on tbl_erp_purchase_returns e_2 (cost=0.00..1.10 rows=1 width=45)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 10" (cost=0.00..79.96 rows=4 width=128)
-> Seq Scan on tbl_erp_collect_tickets e_3 (cost=0.00..79.92 rows=4 width=115)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 11" (cost=0.00..86.17 rows=9 width=128)
-> Seq Scan on tbl_erp_payment_tickets e_4 (cost=0.00..86.08 rows=9 width=114)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::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-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Result (cost=1.89..8.55 rows=2 width=154)
-> Append (cost=1.89..8.53 rows=2 width=204)
-> Hash Join (cost=1.89..4.66 rows=1 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=1 width=25)
-> Seq Scan on tbl_erp_other_collect_ticket_bank_outs e_6 (cost=0.00..1.88 rows=1 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Nested Loop (cost=0.00..3.85 rows=1 width=116)
Join Filter: (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=1 width=53)
Filter: ((bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])) AND (bank_settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (bank_settle_at <= '2026-05-31 23:59:59+08'::timestamp with time zone))
-> 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.37..149.20 rows=5 width=154)
-> Append (cost=1.37..149.15 rows=5 width=204)
-> Hash Join (cost=1.37..4.15 rows=4 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=4 width=25)
-> Seq Scan on tbl_erp_other_payment_ticket_bank_ins e_7 (cost=0.00..1.32 rows=4 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> GroupAggregate (cost=144.92..144.95 rows=1 width=117)
Group Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Sort (cost=144.92..144.92 rows=1 width=67)
Sort Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Nested Loop (cost=138.05..144.91 rows=1 width=67)
-> Hash Right Join (cost=137.91..144.74 rows=1 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.90..137.90 rows=1 width=26)
-> Hash Join (cost=80.21..137.90 rows=1 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=1 width=12)
-> Seq Scan on tbl_erp_payment_tickets p_4 (cost=0.00..80.20 rows=1 width=12)
Filter: (is_payment_settle AND (bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])) AND (bank_settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (bank_settle_at <= '2026-05-31 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=6.98..7.03 rows=1 width=128)
-> GroupAggregate (cost=6.98..7.02 rows=1 width=125)
Group Key: t_4.id, e_8.id
-> Sort (cost=6.98..6.99 rows=1 width=79)
Sort Key: t_4.id, e_8.id
-> Nested Loop Left Join (cost=3.05..6.97 rows=1 width=79)
-> Hash Join (cost=2.90..4.49 rows=1 width=75)
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=2.89..2.89 rows=1 width=53)
-> Hash Right Join (cost=1.71..2.89 rows=1 width=53)
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=1.70..1.70 rows=1 width=49)
-> Seq Scan on tbl_erp_other_income_tickets t_4 (cost=0.00..1.70 rows=1 width=49)
Filter: ((verify_at IS NOT NULL) AND (verify_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (verify_at <= '2026-05-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Index Scan using tbl_users_pkey on tbl_users u (cost=0.14..2.45 rows=1 width=8)
Index Cond: (id = h.user_id)
-> Subquery Scan on "*SELECT* 18" (cost=0.00..3.22 rows=3 width=127)
-> Seq Scan on tbl_erp_cost_tickets e_9 (cost=0.00..3.18 rows=3 width=114)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 19" (cost=0.00..534.60 rows=8 width=127)
-> Seq Scan on tbl_erp_cash_cost_tickets e_10 (cost=0.00..534.50 rows=8 width=116)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 20" (cost=19.45..19.52 rows=1 width=154)
-> GroupAggregate (cost=19.45..19.51 rows=1 width=141)
Group Key: e_11.id
Filter: (COALESCE(sum(s_2.actual_total_amount), '0'::numeric) > '0'::numeric)
-> Sort (cost=19.45..19.46 rows=4 width=44)
Sort Key: e_11.id
-> Hash Right Join (cost=5.27..19.41 rows=4 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=1 width=39)
-> Seq Scan on tbl_erp_sales_gifts e_11 (cost=0.00..5.26 rows=1 width=39)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (status = 2))
-> Subquery Scan on "*SELECT* 21" (cost=0.00..1.19 rows=1 width=128)
-> Seq Scan on tbl_erp_inventory_losts e_12 (cost=0.00..1.18 rows=1 width=115)
Filter: ((wrote_date >= '2026-05-01'::date) AND (wrote_date <= '2026-05-31'::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-05-01'::date) AND (wrote_date <= '2026-05-31'::date) AND (amount > '0'::numeric) AND (status = 2))
-> Subquery Scan on "*SELECT* 23" (cost=18.08..18.84 rows=13 width=130)
-> GroupAggregate (cost=18.08..18.71 rows=13 width=117)
Group Key: t_5.id, e_14.id
-> Sort (cost=18.08..18.14 rows=23 width=55)
Sort Key: t_5.id, e_14.id
-> Nested Loop Left Join (cost=2.86..17.56 rows=23 width=55)
-> Hash Right Join (cost=2.71..11.69 rows=23 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.70..2.70 rows=1 width=47)
-> Hash Join (cost=1.45..2.70 rows=1 width=47)
Hash Cond: (t_5.id = e_14.erp_wage_ticket_id)
-> 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=1.44..1.44 rows=1 width=28)
-> Seq Scan on tbl_erp_wage_ticket_bank_outs e_14 (cost=0.00..1.44 rows=1 width=28)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Index Scan using tbl_users_pkey on tbl_users u_1 (cost=0.14..0.26 rows=1 width=8)
Index Cond: (id = a.user_id)
-> 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-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 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=9.43..9.84 rows=9 width=128)
-> GroupAggregate (cost=9.43..9.75 rows=9 width=115)
Group Key: t_7.id, e_16.id
-> Sort (cost=9.43..9.46 rows=9 width=53)
Sort Key: t_7.id, e_16.id
-> Nested Loop Left Join (cost=2.52..9.29 rows=9 width=53)
-> Hash Right Join (cost=2.38..4.76 rows=9 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.36..2.36 rows=1 width=45)
-> Hash Join (cost=1.19..2.36 rows=1 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=1 width=26)
-> Seq Scan on tbl_erp_personal_tax_bank_outs e_16 (cost=0.00..1.18 rows=1 width=26)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
-> Index Scan using tbl_users_pkey on tbl_users u_3 (cost=0.14..0.50 rows=1 width=8)
Index Cond: (id = a_2.user_id)
-> 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-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 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-05-01 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-05-31 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.21..4.21 rows=26 width=24)
-> Subquery Scan on g (cost=3.62..4.21 rows=26 width=24)
-> HashAggregate (cost=3.62..3.94 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=18)
Filter: (ledger_id = 1)