QUERY PLAN
Aggregate (cost=92.06..92.07 rows=1 width=8)
-> Sort (cost=82.22..83.86 rows=656 width=330)
Sort Key: sci.from_date DESC NULLS LAST, sci.created_at DESC NULLS LAST
-> HashAggregate (cost=44.97..51.53 rows=656 width=330)
Group Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..43.33 rows=656 width=16)
Filter: ((cover_invoice_id IS NULL) AND ((from_date >= '2024-08-01'::date) OR (NOT is_draft)))