QUERY PLAN
Limit (cost=260.69..260.74 rows=20 width=147)
-> Sort (cost=260.69..261.34 rows=258 width=147)
Sort Key: pci.from_date DESC NULLS LAST, pci.created_at DESC
-> HashAggregate (cost=251.25..253.83 rows=258 width=147)
Group Key: pci.id
-> Hash Right Join (cost=186.49..250.60 rows=258 width=147)
Hash Cond: (pcpp.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_products pcpp (cost=0.00..54.85 rows=1885 width=4)
-> Hash (cost=183.27..183.27 rows=258 width=147)
-> Hash Right Join (cost=143.16..183.27 rows=258 width=147)
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=147)
-> Hash Join (cost=77.88..139.93 rows=258 width=147)
Hash Cond: (ip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_inventory_products ip (cost=0.00..61.38 rows=258 width=4)
Filter: (inventory > '0'::numeric)
-> Hash (cost=50.17..50.17 rows=2217 width=147)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..50.17 rows=2217 width=147)
Filter: (cover_invoice_id IS NULL)