QUERY PLAN
Limit (cost=49.90..49.91 rows=1 width=155)
-> Sort (cost=49.90..49.91 rows=1 width=155)
Sort Key: sci.from_date DESC, sci.created_at DESC
-> Group (cost=49.88..49.89 rows=1 width=155)
Group Key: sci.id
-> Sort (cost=49.88..49.89 rows=1 width=155)
Sort Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..49.88 rows=1 width=155)
Filter: ((cover_invoice_id IS NULL) AND (NOT is_cancel) AND ((invoice_type <> '-1'::smallint) OR (invoice_type IS NULL)) AND (contract_id = 4253))