QUERY PLAN
Aggregate (cost=338.96..338.97 rows=1 width=8)
-> Sort (cost=333.44..334.36 rows=368 width=705)
Sort Key: p.in_out_at DESC NULLS LAST, p.updated_at DESC
-> HashAggregate (cost=314.08..317.76 rows=368 width=705)
Group Key: p.id
-> Hash Right Join (cost=297.25..313.16 rows=368 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=292.65..292.65 rows=368 width=24)
-> Hash Join (cost=235.92..292.65 rows=368 width=24)
Hash Cond: (p.id = inventory_filter_eip.product_id)
-> Hash Left Join (cost=205.79..256.94 rows=2122 width=24)
Hash Cond: (epips.project_id = sc.from_project)
-> Hash Right Join (cost=115.82..138.12 rows=2122 width=28)
Hash Cond: (eip.product_id = p.id)
-> Hash Left Join (cost=17.08..37.93 rows=550 width=12)
Hash Cond: (eip.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.50 rows=550 width=32)
-> Hash (cost=14.35..14.35 rows=218 width=8)
-> Hash Right Join (cost=9.90..14.35 rows=218 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.18..7.18 rows=218 width=4)
-> Seq Scan on tbl_erp_purchase_inbounds epis (cost=0.00..7.18 rows=218 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)
-> 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)
-> Hash (cost=25.53..25.53 rows=368 width=4)
-> HashAggregate (cost=17.25..21.85 rows=368 width=4)
Group Key: inventory_filter_eip.product_id
Filter: (sum(inventory_filter_eip.inventory) > '0'::numeric)
-> Seq Scan on tbl_erp_inventory_products inventory_filter_eip (cost=0.00..14.50 rows=550 width=7)
Filter: (product_id IS NOT NULL)