QUERY PLAN
Subquery Scan on sub (cost=202.36..268.27 rows=10 width=163)
Filter: (sub.id = 2326)
-> WindowAgg (cost=202.36..242.92 rows=2028 width=163)
-> Sort (cost=202.36..207.43 rows=2028 width=155)
Sort Key: sub_1.from_date DESC NULLS LAST, sub_1.created_at DESC
-> Subquery Scan on sub_1 (cost=50.40..90.96 rows=2028 width=155)
-> HashAggregate (cost=50.40..70.68 rows=2028 width=155)
Group Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..45.33 rows=2028 width=155)
Filter: (cover_invoice_id IS NULL)