QUERY PLAN
Aggregate (cost=13.00..13.01 rows=1 width=32)
-> Seq Scan on tbl_purchase_contract_invoices (cost=0.00..13.00 rows=1 width=32)
Filter: (((red_invoice_id IS NOT NULL) OR (NOT is_cancel)) AND (contract_id = 3))