QUERY PLAN
Aggregate (cost=214.18..214.19 rows=1 width=32)
-> Nested Loop (cost=197.82..214.18 rows=1 width=5)
-> Nested Loop (cost=197.67..210.56 rows=1 width=9)
Join Filter: (((sum(r_1.amount)) + (sum(r.amount))) < t.amount)
-> Merge Join (cost=197.53..208.95 rows=1 width=85)
Merge Cond: (dt1.object_id = r_1.erp_cost_ticket_id)
-> Nested Loop (cost=42.94..54.26 rows=1 width=49)
-> GroupAggregate (cost=42.65..42.68 rows=1 width=36)
Group Key: r.erp_cost_ticket_id
-> Sort (cost=42.65..42.66 rows=1 width=36)
Sort Key: r.erp_cost_ticket_id
-> Nested Loop (cost=0.28..42.64 rows=1 width=36)
-> Seq Scan on tbl_erp_collect_ticket_payments r (cost=0.00..1.05 rows=5 width=40)
Filter: (erp_cost_ticket_id IS NOT NULL)
-> Index Scan using tbl_erp_collect_tickets_pkey on tbl_erp_collect_tickets t_1 (cost=0.28..8.30 rows=1 width=4)
Index Cond: (id = r.erp_collect_ticket_id)
Filter: ((bank_settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt1 (cost=0.29..11.56 rows=1 width=13)
Index Cond: ((object_id = r.erp_cost_ticket_id) AND (term_id = 18))
Filter: (object_type = 9)
-> GroupAggregate (cost=154.58..154.64 rows=3 width=36)
Group Key: r_1.erp_cost_ticket_id
-> Sort (cost=154.58..154.59 rows=3 width=10)
Sort Key: r_1.erp_cost_ticket_id
-> Hash Join (cost=41.41..154.56 rows=3 width=10)
Hash Cond: (t_2.id = r_1.erp_payment_ticket_id)
-> Seq Scan on tbl_erp_payment_tickets t_2 (cost=0.00..109.27 rows=257 width=4)
Filter: ((bank_settle_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=41.01..41.01 rows=32 width=14)
-> Seq Scan on tbl_erp_payment_ticket_settles r_1 (cost=0.00..41.01 rows=32 width=14)
Filter: (erp_cost_ticket_id IS NOT NULL)
-> Index Scan using tbl_erp_cost_tickets_pkey on tbl_erp_cost_tickets t (cost=0.14..1.59 rows=1 width=9)
Index Cond: (id = dt1.object_id)
Filter: ((verify_at <= '2026-06-30 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Index Scan using tbl_term_taxonomies_pkey on tbl_term_taxonomies tt (cost=0.15..1.88 rows=1 width=4)
Index Cond: (id = dt1.taxonomy_id)
Filter: ((serial_no)::text = '221106'::text)