QUERY PLAN
Subquery Scan on sub (cost=483.34..547.00 rows=11 width=164)
Filter: (sub.id = 1528)
-> WindowAgg (cost=483.34..520.48 rows=2122 width=164)
-> Sort (cost=483.34..488.65 rows=2122 width=156)
Sort Key: sub_1.updated_at DESC
-> Subquery Scan on sub_1 (cost=323.65..366.09 rows=2122 width=156)
-> HashAggregate (cost=323.65..344.87 rows=2122 width=156)
Group Key: p.id
-> Hash Right Join (cost=281.58..318.10 rows=2218 width=156)
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=255.05..255.05 rows=2122 width=160)
-> Hash Left Join (cost=205.62..255.05 rows=2122 width=160)
Hash Cond: (epips.project_id = sc.from_project)
-> Hash Right Join (cost=115.65..136.24 rows=2122 width=164)
Hash Cond: (eip.product_id = p.id)
-> Hash Left Join (cost=16.90..36.15 rows=511 width=12)
Hash Cond: (eip.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..13.11 rows=511 width=32)
-> Hash (cost=14.24..14.24 rows=213 width=8)
-> Hash Right Join (cost=9.79..14.24 rows=213 width=8)
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=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=156)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=156)
-> Hash (cost=68.32..68.32 rows=1732 width=4)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..68.32 rows=1732 width=4)