QUERY PLAN
Limit (cost=197.59..197.64 rows=20 width=137)
-> Sort (cost=197.34..197.98 rows=258 width=137)
Sort Key: pci.from_date DESC NULLS LAST, ip.created_at DESC
-> HashAggregate (cost=184.56..187.14 rows=258 width=137)
Group Key: ip.id, pci.id
-> Hash Right Join (cost=143.16..183.27 rows=258 width=137)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_projects pip (cost=0.00..30.52 rows=1952 width=8)
-> Hash (cost=139.93..139.93 rows=258 width=137)
-> Hash Left Join (cost=77.88..139.93 rows=258 width=137)
Hash Cond: (ip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_inventory_products ip (cost=0.00..61.38 rows=258 width=129)
Filter: (inventory > '0'::numeric)
-> Hash (cost=50.17..50.17 rows=2217 width=12)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..50.17 rows=2217 width=12)