QUERY PLAN
Limit (cost=2709.07..2709.09 rows=10 width=202)
-> Sort (cost=2709.07..2750.88 rows=16726 width=202)
Sort Key: i.from_date DESC, (107), i.id DESC, (0), (0) DESC
-> Hash Left Join (cost=95.23..2347.62 rows=16726 width=202)
Hash Cond: (((107) = g.object_type) AND (i.id = g.object_id) AND ((0) = g.event_type) AND ((0) = g.event_id))
-> Append (cost=89.97..1915.84 rows=16726 width=154)
-> Result (cost=89.97..957.43 rows=7184 width=154)
-> Append (cost=89.97..867.63 rows=7184 width=154)
-> Hash Left Join (cost=89.97..140.76 rows=434 width=117)
Hash Cond: (i.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_invoices i (cost=0.00..49.65 rows=434 width=43)
Filter: ((NOT is_cancel) AND (NOT is_draft) AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)))
-> Hash (cost=68.32..68.32 rows=1732 width=8)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..68.32 rows=1732 width=8)
-> Nested Loop Left Join (cost=0.28..138.08 rows=15 width=117)
-> Seq Scan on tbl_sales_contract_invoices i_1 (cost=0.00..49.65 rows=15 width=43)
Filter: ((NOT is_cancel) AND (NOT is_draft) AND (invoice_type = '-1'::integer))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c_1 (cost=0.28..5.89 rows=1 width=8)
Index Cond: (id = i_1.contract_id)
-> Seq Scan on tbl_purchase_contract_invoices i_2 (cost=0.00..67.19 rows=2002 width=117)
Filter: ((NOT is_cancel) AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)))
-> Seq Scan on tbl_purchase_contract_invoices i_3 (cost=0.00..67.19 rows=4 width=117)
Filter: ((NOT is_cancel) AND (invoice_type = '-1'::integer))
-> Subquery Scan on "*SELECT* 5" (cost=126.75..128.34 rows=53 width=154)
-> HashAggregate (cost=126.75..127.81 rows=53 width=144)
Group Key: c_2.id
-> Hash Right Join (cost=68.98..126.41 rows=68 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=68.32..68.32 rows=53 width=46)
-> Seq Scan on tbl_sales_contracts c_2 (cost=0.00..68.32 rows=53 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)))
-> Subquery Scan on "*SELECT* 6" (cost=91.72..91.76 rows=1 width=154)
-> GroupAggregate (cost=91.72..91.75 rows=1 width=143)
Group Key: c_3.id
-> Sort (cost=91.72..91.72 rows=1 width=47)
Sort Key: c_3.id
-> Hash Right Join (cost=82.15..91.71 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=82.14..82.14 rows=1 width=41)
-> Seq Scan on tbl_purchase_contracts c_3 (cost=0.00..82.14 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 (COALESCE((cost_type)::integer, 1) = 1))
-> Subquery Scan on "*SELECT* 7" (cost=24.59..28.24 rows=146 width=154)
-> HashAggregate (cost=24.59..26.78 rows=146 width=149)
Group Key: e.id
-> Hash Right Join (cost=7.75..21.91 rows=536 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=5.92..5.92 rows=146 width=47)
-> Seq Scan on tbl_erp_sales_outbounds e (cost=0.00..5.92 rows=146 width=47)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 8" (cost=0.00..1.11 rows=4 width=128)
-> Seq Scan on tbl_erp_sales_returns e_1 (cost=0.00..1.07 rows=4 width=117)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 9" (cost=2.21..2.29 rows=3 width=154)
-> HashAggregate (cost=2.21..2.26 rows=3 width=147)
Group Key: e_2.id
-> Hash Right Join (cost=1.11..2.20 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.07..1.07 rows=3 width=45)
-> Seq Scan on tbl_erp_purchase_returns e_2 (cost=0.00..1.07 rows=3 width=45)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 10" (cost=0.00..85.30 rows=2185 width=128)
-> Seq Scan on tbl_erp_collect_tickets e_3 (cost=0.00..63.45 rows=2185 width=115)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 11" (cost=0.00..91.78 rows=2336 width=128)
-> Seq Scan on tbl_erp_payment_tickets e_4 (cost=0.00..68.42 rows=2336 width=114)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 12" (cost=0.00..1.05 rows=1 width=127)
-> Seq Scan on tbl_erp_advance_payment_tickets e_5 (cost=0.00..1.04 rows=1 width=115)
Filter: (status = 2)
-> Result (cost=3.14..9.51 rows=41 width=154)
-> Append (cost=3.14..9.10 rows=41 width=204)
-> Hash Join (cost=3.14..4.91 rows=40 width=116)
Hash Cond: (e_6.erp_other_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_other_collect_ticket_bank_outs e_6 (cost=0.00..1.55 rows=43 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=2.59..2.59 rows=44 width=45)
-> 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 Join (cost=1.02..3.77 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.59 rows=40 width=53)
Filter: ((bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])))
-> 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)
-> Result (cost=1.40..165.72 rows=273 width=154)
-> Append (cost=1.40..162.99 rows=273 width=204)
-> Hash Join (cost=1.40..4.33 rows=16 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.20..1.20 rows=16 width=25)
-> Seq Scan on tbl_erp_other_payment_ticket_bank_ins e_7 (cost=0.00..1.20 rows=16 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> GroupAggregate (cost=148.22..155.93 rows=257 width=117)
Group Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Sort (cost=148.22..148.86 rows=257 width=67)
Sort Key: s_1.id, t_3.id, p_4.bank_settle_at
-> Hash Left Join (cost=83.89..137.93 rows=257 width=67)
Hash Cond: (p_4.id = bo.erp_payment_ticket_id)
-> Hash Join (cost=74.64..127.09 rows=257 width=67)
Hash Cond: (s_1.erp_other_payment_ticket_id = t_3.id)
-> Hash Join (cost=71.62..123.40 rows=257 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..45.56 rows=2364 width=18)
Filter: (amount > '0'::numeric)
-> Hash (cost=68.42..68.42 rows=256 width=12)
-> Seq Scan on tbl_erp_payment_tickets p_4 (cost=0.00..68.42 rows=256 width=12)
Filter: (is_payment_settle AND (bank_settle_at IS NOT NULL) AND (status = ANY ('{2,5}'::integer[])))
-> Hash (cost=2.45..2.45 rows=45 width=45)
-> Seq Scan on tbl_erp_other_payment_tickets t_3 (cost=0.00..2.45 rows=45 width=45)
-> Hash (cost=5.78..5.78 rows=278 width=8)
-> Seq Scan on tbl_erp_payment_ticket_bank_outs bo (cost=0.00..5.78 rows=278 width=8)
-> Subquery Scan on "*SELECT* 17" (cost=14.33..15.55 rows=27 width=128)
-> GroupAggregate (cost=14.33..15.28 rows=27 width=125)
Group Key: t_4.id, e_8.id
-> Sort (cost=14.33..14.40 rows=27 width=79)
Sort Key: t_4.id, e_8.id
-> Hash Right Join (cost=5.07..13.69 rows=27 width=79)
Hash Cond: (h.erp_other_income_ticket_id = t_4.id)
-> Hash Right Join (cost=1.32..9.79 rows=14 width=12)
Hash Cond: (u.id = h.user_id)
-> Seq Scan on tbl_users u (cost=0.00..7.44 rows=144 width=8)
-> Hash (cost=1.14..1.14 rows=14 width=8)
-> Seq Scan on tbl_erp_other_income_ticket_handlers h (cost=0.00..1.14 rows=14 width=8)
-> Hash (cost=3.42..3.42 rows=27 width=71)
-> Hash Join (cost=1.94..3.42 rows=27 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.39 rows=31 width=26)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=1.50..1.50 rows=35 width=49)
-> Seq Scan on tbl_erp_other_income_tickets t_4 (cost=0.00..1.50 rows=35 width=49)
Filter: ((verify_at IS NOT NULL) AND (status = 2))
-> Subquery Scan on "*SELECT* 18" (cost=0.00..3.39 rows=52 width=127)
-> Seq Scan on tbl_erp_cost_tickets e_9 (cost=0.00..2.74 rows=52 width=114)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 19" (cost=0.00..576.75 rows=8465 width=127)
-> Seq Scan on tbl_erp_cash_cost_tickets e_10 (cost=0.00..470.94 rows=8465 width=116)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 20" (cost=22.95..26.00 rows=122 width=154)
-> HashAggregate (cost=22.95..24.48 rows=122 width=141)
Group Key: e_11.id
-> Hash Right Join (cost=6.14..20.28 rows=534 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=4.61..4.61 rows=122 width=39)
-> Seq Scan on tbl_erp_sales_gifts e_11 (cost=0.00..4.61 rows=122 width=39)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 21" (cost=0.00..1.18 rows=5 width=128)
-> Seq Scan on tbl_erp_inventory_losts e_12 (cost=0.00..1.11 rows=5 width=115)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 22" (cost=0.00..1.19 rows=5 width=127)
-> Seq Scan on tbl_erp_inventory_overflows e_13 (cost=0.00..1.12 rows=5 width=114)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 23" (cost=45.38..60.89 rows=286 width=130)
-> GroupAggregate (cost=45.38..58.03 rows=286 width=117)
Group Key: t_5.id, e_14.id
-> Sort (cost=45.38..46.47 rows=437 width=55)
Sort Key: t_5.id, e_14.id
-> Hash Right Join (cost=12.17..26.21 rows=437 width=55)
Hash Cond: (a.erp_wage_ticket_id = t_5.id)
-> Hash Left Join (cost=9.24..17.62 rows=345 width=12)
Hash Cond: (a.user_id = u_1.id)
-> Seq Scan on tbl_erp_wage_ticket_amounts a (cost=0.00..7.45 rows=345 width=8)
-> 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)
-> Hash (cost=2.69..2.69 rows=19 width=47)
-> Hash Join (cost=1.35..2.69 rows=19 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.27 rows=22 width=28)
Filter: ((settle_at IS NOT NULL) 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[]))
-> Subquery Scan on "*SELECT* 24" (cost=28.65..35.18 rows=110 width=130)
-> GroupAggregate (cost=28.65..34.08 rows=110 width=117)
Group Key: t_6.id, e_15.id
-> Sort (cost=28.65..29.15 rows=200 width=55)
Sort Key: t_6.id, e_15.id
-> Hash Left Join (cost=11.80..21.01 rows=200 width=55)
Hash Cond: (a_1.user_id = u_2.id)
-> Hash Right Join (cost=2.56..11.23 rows=200 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.45..2.45 rows=9 width=47)
-> Hash Join (cost=1.29..2.45 rows=9 width=47)
Hash Cond: (e_15.erp_social_insurance_id = t_6.id)
-> Seq Scan on tbl_erp_social_insurance_bank_outs e_15 (cost=0.00..1.12 rows=10 width=28)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=1.15..1.15 rows=11 width=23)
-> 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=7.44..7.44 rows=144 width=8)
-> Seq Scan on tbl_users u_2 (cost=0.00..7.44 rows=144 width=8)
-> Subquery Scan on "*SELECT* 25" (cost=17.85..21.68 rows=85 width=128)
-> GroupAggregate (cost=17.85..20.83 rows=85 width=115)
Group Key: t_7.id, e_16.id
-> Sort (cost=17.85..18.06 rows=85 width=53)
Sort Key: t_7.id, e_16.id
-> Hash Left Join (cost=11.75..15.13 rows=85 width=53)
Hash Cond: (a_2.user_id = u_3.id)
-> Hash Right Join (cost=2.51..5.65 rows=85 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.40..2.40 rows=9 width=45)
-> Hash Join (cost=1.25..2.40 rows=9 width=45)
Hash Cond: (e_16.erp_personal_tax_id = t_7.id)
-> Seq Scan on tbl_erp_personal_tax_bank_outs e_16 (cost=0.00..1.11 rows=9 width=26)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=1.12..1.12 rows=10 width=23)
-> 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=7.44..7.44 rows=144 width=8)
-> Seq Scan on tbl_users u_3 (cost=0.00..7.44 rows=144 width=8)
-> Subquery Scan on "*SELECT* 26" (cost=11.74..12.10 rows=8 width=129)
-> GroupAggregate (cost=11.74..12.02 rows=8 width=116)
Group Key: t_8.id, e_17.id
-> Sort (cost=11.74..11.76 rows=8 width=54)
Sort Key: t_8.id, e_17.id
-> Hash Right Join (cost=3.45..11.62 rows=8 width=54)
Hash Cond: (a_3.erp_wage_prize_id = t_8.id)
-> Hash Right Join (cost=1.18..9.24 rows=8 width=12)
Hash Cond: (u_4.id = a_3.user_id)
-> Seq Scan on tbl_users u_4 (cost=0.00..7.44 rows=144 width=8)
-> Hash (cost=1.08..1.08 rows=8 width=8)
-> Seq Scan on tbl_erp_wage_prize_amounts a_3 (cost=0.00..1.08 rows=8 width=8)
-> Hash (cost=2.21..2.21 rows=5 width=46)
-> Hash Join (cost=1.12..2.21 rows=5 width=46)
Hash Cond: (e_17.erp_wage_prize_id = t_8.id)
-> Seq Scan on tbl_erp_wage_prize_bank_outs e_17 (cost=0.00..1.06 rows=5 width=27)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=1.06..1.06 rows=5 width=23)
-> Seq Scan on tbl_erp_wage_prizes t_8 (cost=0.00..1.06 rows=5 width=23)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Subquery Scan on "*SELECT* 27" (cost=24.69..29.29 rows=63 width=129)
-> GroupAggregate (cost=24.69..28.66 rows=63 width=117)
Group Key: t_9.id, e_18.id
-> Sort (cost=24.69..25.10 rows=164 width=55)
Sort Key: t_9.id, e_18.id
-> Hash Left Join (cost=11.67..18.65 rows=164 width=55)
Hash Cond: (a_4.user_id = u_5.id)
-> Hash Right Join (cost=2.43..8.97 rows=164 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.34..2.34 rows=7 width=47)
-> Hash Join (cost=1.23..2.34 rows=7 width=47)
Hash Cond: (e_18.erp_provident_fund_id = t_9.id)
-> Seq Scan on tbl_erp_provident_fund_bank_outs e_18 (cost=0.00..1.09 rows=7 width=27)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric))
-> Hash (cost=1.11..1.11 rows=9 width=24)
-> 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=7.44..7.44 rows=144 width=8)
-> Seq Scan on tbl_users u_5 (cost=0.00..7.44 rows=144 width=8)
-> 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)