QUERY PLAN
Aggregate (cost=89.03..89.04 rows=1 width=8)
-> Sort (cost=79.70..81.26 rows=622 width=330)
Sort Key: sci.from_date DESC NULLS LAST, sci.created_at DESC NULLS LAST
-> HashAggregate (cost=44.62..50.84 rows=622 width=330)
Group Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..43.06 rows=622 width=16)
Filter: ((cover_invoice_id IS NULL) AND ((from_date >= '2024-08-01'::date) OR (NOT is_draft)))