QUERY PLAN
Subquery Scan on sub (cost=194.87..258.21 rows=10 width=163)
Filter: (sub.id = 2327)
-> WindowAgg (cost=194.87..233.85 rows=1949 width=163)
-> Sort (cost=194.87..199.74 rows=1949 width=155)
Sort Key: sub_1.from_date DESC NULLS LAST, sub_1.created_at DESC
-> Subquery Scan on sub_1 (cost=49.39..88.37 rows=1949 width=155)
-> HashAggregate (cost=49.39..68.88 rows=1949 width=155)
Group Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..44.52 rows=1949 width=155)
Filter: (cover_invoice_id IS NULL)