QUERY PLAN
Aggregate (cost=152.78..152.79 rows=1 width=32)
-> Nested Loop (cost=131.56..152.78 rows=1 width=5)
Join Filter: (dt1.taxonomy_id = tt.id)
-> Nested Loop (cost=131.56..144.96 rows=1 width=9)
-> Nested Loop (cost=131.27..133.80 rows=1 width=12)
Join Filter: ((t.id = r.erp_cost_ticket_id) AND (((sum(r.amount)) + (sum(r_1.amount))) < t.amount))
-> GroupAggregate (cost=113.40..113.42 rows=1 width=36)
Group Key: r.erp_cost_ticket_id
-> Sort (cost=113.40..113.40 rows=1 width=10)
Sort Key: r.erp_cost_ticket_id
-> Hash Join (cost=38.65..113.39 rows=1 width=10)
Hash Cond: (t_1.id = r.erp_payment_ticket_id)
-> Seq Scan on tbl_erp_payment_tickets t_1 (cost=0.00..73.12 rows=117 width=4)
Filter: ((bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=38.50..38.50 rows=12 width=14)
-> Seq Scan on tbl_erp_payment_ticket_settles r (cost=0.00..38.50 rows=12 width=14)
Filter: (erp_cost_ticket_id IS NOT NULL)
-> Hash Join (cost=17.87..20.35 rows=1 width=45)
Hash Cond: (t.id = r_1.erp_cost_ticket_id)
-> Seq Scan on tbl_erp_cost_tickets t (cost=0.00..2.40 rows=23 width=9)
Filter: ((verify_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=17.86..17.86 rows=1 width=36)
-> GroupAggregate (cost=17.83..17.85 rows=1 width=36)
Group Key: r_1.erp_cost_ticket_id
-> Sort (cost=17.83..17.83 rows=1 width=36)
Sort Key: r_1.erp_cost_ticket_id
-> Nested Loop (cost=0.28..17.82 rows=1 width=36)
-> Seq Scan on tbl_erp_collect_ticket_payments r_1 (cost=0.00..1.02 rows=2 width=40)
Filter: (erp_cost_ticket_id IS NOT NULL)
-> Index Scan using tbl_erp_collect_tickets_pkey on tbl_erp_collect_tickets t_2 (cost=0.28..8.30 rows=1 width=4)
Index Cond: (id = r_1.erp_collect_ticket_id)
Filter: ((bank_settle_at <= '2025-12-31 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.16 rows=1 width=13)
Index Cond: ((object_id = t.id) AND (term_id = 18))
Filter: (object_type = 9)
-> Seq Scan on tbl_term_taxonomies tt (cost=0.00..7.80 rows=1 width=4)
Filter: ((serial_no)::text = '221106'::text)