QUERY PLAN
Aggregate (cost=245.07..245.08 rows=1 width=8)
-> Sort (cost=236.43..237.87 rows=576 width=895)
Sort Key: pci.from_date DESC NULLS LAST, ip.created_at DESC
-> HashAggregate (cost=204.26..210.02 rows=576 width=895)
Group Key: ip.id, pci.id
-> Hash Right Join (cost=157.90..201.38 rows=576 width=20)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_projects pip (cost=0.00..30.94 rows=1994 width=8)
-> Hash (cost=150.70..150.70 rows=576 width=20)
-> Hash Left Join (cost=79.98..150.70 rows=576 width=20)
Hash Cond: (ip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_inventory_products ip (cost=0.00..69.20 rows=576 width=16)
Filter: (inventory > '0'::numeric)
-> Hash (cost=51.66..51.66 rows=2266 width=12)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..51.66 rows=2266 width=12)