QUERY PLAN
Subquery Scan on sub (cost=43.11..43.18 rows=1 width=163)
Filter: (sub.idx = '2'::bigint)
-> WindowAgg (cost=43.11..43.15 rows=2 width=163)
-> Sort (cost=43.11..43.12 rows=2 width=155)
Sort Key: sub_1.from_date DESC NULLS LAST, sub_1.created_at DESC NULLS LAST
-> Subquery Scan on sub_1 (cost=43.07..43.10 rows=2 width=155)
-> Group (cost=43.07..43.08 rows=2 width=155)
Group Key: sci.id
-> Sort (cost=43.07..43.08 rows=2 width=155)
Sort Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..43.06 rows=2 width=155)
Filter: ((cover_invoice_id IS NULL) AND (invoice_type = '2'::smallint))