QUERY PLAN
Aggregate (cost=13.20..13.21 rows=1 width=8)
-> Sort (cost=13.18..13.18 rows=1 width=346)
Sort Key: sci.from_date DESC, sci.created_at DESC
-> Group (cost=13.16..13.17 rows=1 width=346)
Group Key: sci.id
-> Sort (cost=13.16..13.17 rows=1 width=16)
Sort Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..13.15 rows=1 width=16)
Filter: ((cover_invoice_id IS NULL) AND (NOT is_cancel) AND ((invoice_type <> '-1'::smallint) OR (invoice_type IS NULL)) AND (contract_id = 8))