QUERY PLAN
Limit (cost=55.10..55.10 rows=1 width=164)
-> Sort (cost=55.10..55.10 rows=1 width=164)
Sort Key: "*SELECT* 1".bill_date DESC, "*SELECT* 1".object_type, "*SELECT* 1".object_id DESC, "*SELECT* 1".event_type, "*SELECT* 1".event_id DESC
-> Hash Left Join (cost=7.16..55.09 rows=1 width=164)
Hash Cond: (("*SELECT* 1".object_type = g.object_type) AND ("*SELECT* 1".object_id = g.object_id) AND ("*SELECT* 1".event_type = g.event_type) AND ("*SELECT* 1".event_id = g.event_id))
Filter: ((g.success_count IS NULL) OR (g.success_count = 0))
-> Append (cost=1.89..49.79 rows=2 width=116)
-> Subquery Scan on "*SELECT* 1" (cost=1.89..25.30 rows=1 width=116)
Filter: (("*SELECT* 1".object_type <> ALL ('{20,20018}'::integer[])) OR "*SELECT* 1".have_invoice OR (SubPlan 1))
-> Hash Join (cost=1.89..4.66 rows=1 width=116)
Hash Cond: (t.id = e.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 (cost=0.00..1.88 rows=1 width=25)
Filter: ((settle_at IS NOT NULL) AND (amount > '0'::numeric) AND (settle_at >= '2026-01-26 00:00:00+08'::timestamp with time zone) AND (settle_at <= '2026-01-26 23:59:59+08'::timestamp with time zone) AND (amount > '0'::numeric))
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 = "*SELECT* 1".object_id) AND (term_id = 18))
Filter: ((("*SELECT* 1".object_type = 20) AND (object_type = 7)) OR (("*SELECT* 1".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[]))
-> Subquery Scan on "*SELECT* 2" (cost=0.00..24.49 rows=1 width=116)
Filter: (("*SELECT* 2".object_type <> ALL ('{20,20018}'::integer[])) OR "*SELECT* 2".have_invoice OR (SubPlan 1))
-> Nested Loop (cost=0.00..3.85 rows=1 width=116)
Join Filter: (t_1.id = p.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-01-26 00:00:00+08'::timestamp with time zone) AND (bank_settle_at <= '2026-01-26 23:59:59+08'::timestamp with time zone))
-> Seq Scan on tbl_erp_other_collect_ticket_payments p (cost=0.00..1.01 rows=1 width=13)
Filter: ((amount > '0'::numeric) AND (amount > '0'::numeric))
-> 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)