QUERY PLAN
Limit (cost=89.87..89.88 rows=3 width=165)
-> Sort (cost=89.87..89.88 rows=3 width=165)
Sort Key: (COALESCE(i.verify_at, i.from_date)) DESC, i.id DESC
-> Nested Loop Left Join (cost=3.23..89.85 rows=3 width=165)
Join Filter: (g.object_id = i.id)
Filter: ((g.success_count IS NULL) OR (g.success_count = 0))
-> Seq Scan on tbl_purchase_contract_invoices i (cost=0.00..86.50 rows=3 width=52)
Filter: ((NOT is_cancel) AND is_verify AND ((invoice_type <> '-1'::integer) OR (invoice_type IS NULL)) AND (COALESCE(verify_at, from_date) >= '2026-06-01'::date) AND (COALESCE(verify_at, from_date) <= '2026-06-30'::date) AND (amount > '0'::numeric))
-> 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 = 109) AND (COALESCE(event_id, 0) = 0) AND (COALESCE((event_type)::integer, 0) = 0))