QUERY PLAN
Aggregate (cost=948.88..948.89 rows=1 width=8)
-> Group (cost=948.37..948.52 rows=29 width=673)
Group Key: p.id
-> Sort (cost=948.37..948.44 rows=29 width=4)
Sort Key: p.id
-> Hash Right Join (cost=751.40..947.67 rows=29 width=4)
Hash Cond: (sp.id = esos.project_id)
Filter: ((pp.created_by = ANY ('{1001,5311,5295}'::integer[])) OR (sp.created_by = ANY ('{1001,5311,5295}'::integer[])))
-> Seq Scan on tbl_projects sp (cost=0.00..178.82 rows=3182 width=8)
-> Hash (cost=750.30..750.30 rows=88 width=12)
-> Hash Left Join (cost=685.25..750.30 rows=88 width=12)
Hash Cond: (esosps.erp_sales_outbound_id = esos.id)
-> Hash Left Join (cost=675.93..740.75 rows=88 width=12)
Hash Cond: (eip.id = esosps.erp_inventory_product_id)
-> Hash Join (cost=658.91..721.23 rows=88 width=12)
Hash Cond: (p.id = inventory_filter_eip.product_id)
-> Hash Left Join (cost=426.15..482.89 rows=2122 width=12)
Hash Cond: (epips.project_id = sc.from_project)
-> Hash Left Join (cost=334.42..362.30 rows=2122 width=16)
Hash Cond: (epips.project_id = pp.id)
-> Hash Right Join (cost=115.82..138.12 rows=2122 width=12)
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=20)
-> Seq Scan on tbl_products p (cost=0.00..72.22 rows=2122 width=20)
-> Hash (cost=178.82..178.82 rows=3182 width=8)
-> Seq Scan on tbl_projects pp (cost=0.00..178.82 rows=3182 width=8)
-> Hash (cost=69.66..69.66 rows=1766 width=4)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..69.66 rows=1766 width=4)
-> Hash (cost=231.66..231.66 rows=88 width=4)
-> HashAggregate (cost=229.68..230.78 rows=88 width=4)
Group Key: inventory_filter_eip.product_id
Filter: (sum(inventory_filter_eip.inventory) > '0'::numeric)
-> Hash Join (cost=213.29..229.24 rows=88 width=7)
Hash Cond: (inventory_filter_eip.id = inventory_sales_rep_eip.id)
-> Seq Scan on tbl_erp_inventory_products inventory_filter_eip (cost=0.00..14.50 rows=550 width=11)
Filter: (product_id IS NOT NULL)
-> Hash (cost=212.19..212.19 rows=88 width=4)
-> HashAggregate (cost=210.43..211.31 rows=88 width=4)
Group Key: inventory_sales_rep_eip.id
-> Hash Join (cost=192.95..210.21 rows=88 width=4)
Hash Cond: (inventory_sales_rep_eip.erp_purchase_inbound_id = inventory_sales_rep_inbound.id)
-> Seq Scan on tbl_erp_inventory_products inventory_sales_rep_eip (cost=0.00..14.50 rows=550 width=8)
-> Hash (cost=192.52..192.52 rows=35 width=8)
-> Hash Join (cost=184.17..192.52 rows=35 width=8)
Hash Cond: (inventory_sales_rep_inbound.id = inventory_sales_rep_inbound_project.erp_purchase_inbound_id)
-> Seq Scan on tbl_erp_purchase_inbounds inventory_sales_rep_inbound (cost=0.00..7.18 rows=218 width=4)
-> Hash (cost=183.73..183.73 rows=35 width=4)
-> Hash Join (cost=179.30..183.73 rows=35 width=4)
Hash Cond: (inventory_sales_rep_inbound_project.project_id = inventory_sales_rep_project.id)
-> Seq Scan on tbl_erp_purchase_inbound_projects inventory_sales_rep_inbound_project (cost=0.00..3.93 rows=193 width=8)
-> Hash (cost=172.15..172.15 rows=572 width=4)
-> Bitmap Heap Scan on tbl_projects inventory_sales_rep_project (cost=17.28..172.15 rows=572 width=4)
Recheck Cond: (created_by = ANY ('{1001,5311,5295}'::integer[]))
-> Bitmap Index Scan on tbl_projects_created_by_idx (cost=0.00..17.14 rows=572 width=0)
Index Cond: (created_by = ANY ('{1001,5311,5295}'::integer[]))
-> Hash (cost=10.34..10.34 rows=534 width=8)
-> Seq Scan on tbl_erp_sales_outbound_spent_products esosps (cost=0.00..10.34 rows=534 width=8)
-> Hash (cost=6.92..6.92 rows=192 width=8)
-> Seq Scan on tbl_erp_sales_outbounds esos (cost=0.00..6.92 rows=192 width=8)