QUERY PLAN
Limit (cost=517.88..517.95 rows=29 width=164)
-> Sort (cost=517.88..517.95 rows=29 width=164)
Sort Key: e.wrote_date DESC, e.id DESC
-> Nested Loop Left Join (cost=3.23..517.17 rows=29 width=164)
Join Filter: (g.object_id = e.id)
-> Seq Scan on tbl_erp_cash_cost_tickets e (cost=0.00..513.31 rows=29 width=47)
Filter: ((wrote_date >= '2026-03-05'::date) AND (wrote_date <= '2026-06-30'::date) AND (status = 2))
-> Materialize (cost=3.23..3.28 rows=1 width=24)
-> Subquery Scan on g (cost=3.23..3.28 rows=1 width=24)
-> GroupAggregate (cost=3.23..3.27 rows=1 width=36)
Group Key: v.object_type, v.object_id, (COALESCE((v.event_type)::integer, 0)), (COALESCE(v.event_id, 0))
-> Sort (cost=3.23..3.23 rows=1 width=22)
Sort Key: v.object_id
-> Seq Scan on tbl_voucher_gen_items v (cost=0.00..3.22 rows=1 width=22)
Filter: ((ledger_id = 1) AND (object_type = 20018) AND (COALESCE(event_id, 0) = 0) AND (COALESCE((event_type)::integer, 0) = 0))