QUERY PLAN
Subquery Scan on sub (cost=174.60..232.45 rows=9 width=163)
Filter: (sub.id = 2115)
-> WindowAgg (cost=174.60..210.20 rows=1780 width=163)
-> Sort (cost=174.60..179.05 rows=1780 width=155)
Sort Key: sub_1.from_date DESC NULLS LAST, sub_1.created_at DESC NULLS LAST
-> Subquery Scan on sub_1 (cost=42.90..78.50 rows=1780 width=155)
-> HashAggregate (cost=42.90..60.70 rows=1780 width=155)
Group Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..38.45 rows=1780 width=155)
Filter: (cover_invoice_id IS NULL)