QUERY PLAN
Aggregate (cost=337.31..337.32 rows=1 width=32)
-> Hash Join (cost=270.84..336.68 rows=248 width=3)
Hash Cond: (tbl_inventory_products.id = "ANY_subquery".id)
-> Seq Scan on tbl_inventory_products (cost=0.00..61.79 rows=496 width=7)
Filter: (inventory > '0'::numeric)
-> Hash (cost=268.34..268.34 rows=200 width=4)
-> HashAggregate (cost=266.34..268.34 rows=200 width=4)
Group Key: "ANY_subquery".id
-> Subquery Scan on "ANY_subquery" (cost=225.32..261.78 rows=1823 width=4)
-> HashAggregate (cost=225.32..243.55 rows=1823 width=8)
Group Key: ip.id, pci.id
-> Hash Right Join (cost=162.43..216.20 rows=1823 width=8)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_projects pip (cost=0.00..30.43 rows=1943 width=8)
-> Hash (cost=139.64..139.64 rows=1823 width=8)
-> Hash Left Join (cost=77.61..139.64 rows=1823 width=8)
Hash Cond: (ip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_inventory_products ip (cost=0.00..57.23 rows=1823 width=8)
-> Hash (cost=50.05..50.05 rows=2205 width=8)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..50.05 rows=2205 width=8)