QUERY PLAN
Aggregate (cost=226.84..226.85 rows=1 width=8)
-> Sort (cost=226.09..226.22 rows=50 width=705)
Sort Key: p.in_out_at DESC NULLS LAST, p.updated_at DESC
-> GroupAggregate (cost=223.93..224.68 rows=50 width=705)
Group Key: p.id
-> Sort (cost=223.93..224.05 rows=50 width=20)
Sort Key: p.id
-> Hash Right Join (cost=209.68..222.52 rows=50 width=20)
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=209.08..209.08 rows=48 width=24)
-> Hash Right Join (cost=129.46..209.08 rows=48 width=24)
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=128.86..128.86 rows=48 width=28)
-> Hash Join (cost=123.65..128.86 rows=48 width=28)
Hash Cond: (eip.product_id = p.id)
-> Hash Right Join (cost=24.91..29.99 rows=48 width=12)
Hash Cond: (epips.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_purchase_inbound_projects epips (cost=0.00..3.93 rows=193 width=8)
-> Hash (cost=24.31..24.31 rows=48 width=12)
-> Hash Left Join (cost=9.79..24.31 rows=48 width=12)
Hash Cond: (eip.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.39 rows=48 width=32)
Filter: (inventory > '0'::numeric)
-> 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=72.22..72.22 rows=2122 width=36)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=36)