QUERY PLAN
Limit (cost=8.33..8.33 rows=1 width=155)
-> Sort (cost=8.33..8.33 rows=1 width=155)
Sort Key: sci.from_date DESC, sci.created_at DESC
-> Group (cost=8.31..8.32 rows=1 width=155)
Group Key: sci.id
-> Sort (cost=8.31..8.31 rows=1 width=155)
Sort Key: sci.id
-> Index Scan using tbl_sales_contract_invoices_contract_id_idx on tbl_sales_contract_invoices sci (cost=0.28..8.30 rows=1 width=155)
Index Cond: (contract_id = 4492)
Filter: ((cover_invoice_id IS NULL) AND (NOT is_cancel) AND ((invoice_type <> '-1'::smallint) OR (invoice_type IS NULL)))