QUERY PLAN
Aggregate (cost=233.40..233.41 rows=1 width=8)
-> Sort (cost=232.44..232.60 rows=64 width=673)
Sort Key: p.updated_at DESC
-> Group (cost=230.20..230.52 rows=64 width=673)
Group Key: p.id
-> Sort (cost=230.20..230.36 rows=64 width=12)
Sort Key: p.id
-> Hash Right Join (cost=215.29..228.28 rows=64 width=12)
Hash Cond: (esosps.erp_inventory_product_id = eip.id)
-> Seq Scan on tbl_erp_sales_outbound_spent_products esosps (cost=0.00..10.34 rows=534 width=8)
-> Hash (cost=214.49..214.49 rows=64 width=16)
-> Hash Right Join (cost=132.55..214.49 rows=64 width=16)
Hash Cond: (sc.from_project = epips.project_id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..68.32 rows=1732 width=4)
-> Hash (cost=131.75..131.75 rows=64 width=20)
-> Hash Left Join (cost=114.88..131.75 rows=64 width=20)
Hash Cond: (epis.id = epips.erp_purchase_inbound_id)
-> Hash Left Join (cost=108.54..124.51 rows=64 width=20)
Hash Cond: (eip.erp_purchase_inbound_id = epis.id)
-> Hash Join (cost=98.75..114.55 rows=64 width=20)
Hash Cond: (eip.product_id = p.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..15.64 rows=64 width=32)
Filter: (inventory > '0'::numeric)
-> Hash (cost=72.22..72.22 rows=2122 width=28)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=28)
-> Hash (cost=7.13..7.13 rows=213 width=4)
-> Seq Scan on tbl_erp_purchase_inbounds epis (cost=0.00..7.13 rows=213 width=4)
-> Hash (cost=3.93..3.93 rows=193 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_projects epips (cost=0.00..3.93 rows=193 width=8)