QUERY PLAN
Aggregate (cost=355.79..355.80 rows=1 width=128)
-> Hash Join (cost=327.09..347.53 rows=550 width=10)
Hash Cond: (eip.product_id = p.id)
-> Hash Left Join (cost=1.04..20.04 rows=550 width=14)
Hash Cond: (eip.erp_store_id = count_saleable_store.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.50 rows=550 width=16)
-> Hash (cost=1.02..1.02 rows=2 width=6)
-> Seq Scan on tbl_erp_stores count_saleable_store (cost=0.00..1.02 rows=2 width=6)
-> Hash (cost=321.44..321.44 rows=368 width=4)
-> HashAggregate (cost=314.08..317.76 rows=368 width=4)
Group Key: p.id
-> Hash Right Join (cost=297.25..313.16 rows=368 width=4)
Hash Cond: (esosps.erp_inventory_product_id = eip_1.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=8)
-> Hash Join (cost=235.92..292.65 rows=368 width=8)
Hash Cond: (p.id = inventory_filter_eip.product_id)
-> Hash Left Join (cost=205.79..256.94 rows=2122 width=8)
Hash Cond: (epips.project_id = sc.from_project)
-> Hash Right Join (cost=115.82..138.12 rows=2122 width=12)
Hash Cond: (eip_1.product_id = p.id)
-> Hash Left Join (cost=17.08..37.93 rows=550 width=12)
Hash Cond: (eip_1.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_inventory_products eip_1 (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=20)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=20)
-> 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)