QUERY PLAN
Aggregate (cost=329.23..329.24 rows=1 width=64)
-> GroupAggregate (cost=328.33..329.20 rows=2 width=68)
Group Key: eip.product_id
-> Merge Join (cost=328.33..329.15 rows=2 width=13)
Merge Cond: (eip.product_id = p.id)
-> Sort (cost=59.44..59.48 rows=14 width=13)
Sort Key: eip.product_id
-> Nested Loop (cost=35.62..59.17 rows=14 width=13)
-> Hash Left Join (cost=35.35..53.54 rows=14 width=13)
Hash Cond: (eips.erp_inventory_disassemble_spent_id = eid.id)
Filter: (((eips.erp_sales_outbound_id IS NOT NULL) AND (esos.status = 1)) OR ((eips.erp_sales_gift_id IS NOT NULL) AND (esg.status = 1)) OR ((eips.erp_inventory_lost_id IS NOT NULL) AND (eil.status = 1)) OR ((eips.erp_inventory_build_spent_id IS NOT NULL) AND (eib.status = 1)) OR ((eips.erp_inventory_disassemble_spent_id IS NOT NULL) AND (eid.status = 1)))
-> Hash Left Join (cost=21.30..38.37 rows=428 width=41)
Hash Cond: (eips.erp_inventory_build_spent_id = eib.id)
-> Hash Left Join (cost=20.26..36.19 rows=428 width=39)
Hash Cond: (eips.erp_inventory_lost_id = eil.id)
-> Hash Left Join (cost=19.19..33.98 rows=428 width=37)
Hash Cond: (eips.erp_sales_gift_id = esg.id)
-> Hash Left Join (cost=10.42..24.08 rows=428 width=35)
Hash Cond: (eips.erp_sales_outbound_id = esos.id)
-> Seq Scan on tbl_erp_inventory_product_spents eips (cost=0.00..12.51 rows=428 width=33)
Filter: ((erp_sales_outbound_id IS NOT NULL) OR (erp_sales_gift_id IS NOT NULL) OR (erp_inventory_lost_id IS NOT NULL) OR (erp_inventory_build_spent_id IS NOT NULL) OR (erp_inventory_disassemble_spent_id IS NOT NULL))
-> Hash (cost=8.52..8.52 rows=152 width=6)
-> Seq Scan on tbl_erp_sales_outbounds esos (cost=0.00..8.52 rows=152 width=6)
-> Hash (cost=7.23..7.23 rows=123 width=6)
-> Seq Scan on tbl_erp_sales_gifts esg (cost=0.00..7.23 rows=123 width=6)
-> Hash (cost=1.03..1.03 rows=3 width=6)
-> Seq Scan on tbl_erp_inventory_losts eil (cost=0.00..1.03 rows=3 width=6)
-> Hash (cost=1.02..1.02 rows=2 width=6)
-> Seq Scan on tbl_erp_inventory_builds eib (cost=0.00..1.02 rows=2 width=6)
-> Hash (cost=11.80..11.80 rows=180 width=6)
-> Seq Scan on tbl_erp_inventory_disassembles eid (cost=0.00..11.80 rows=180 width=6)
-> Index Scan using tbl_erp_inventory_products_pkey on tbl_erp_inventory_products eip (cost=0.27..0.40 rows=1 width=8)
Index Cond: (id = eips.erp_inventory_product_id)
-> Group (cost=268.89..269.10 rows=42 width=4)
Group Key: p.id
-> Sort (cost=268.89..268.99 rows=42 width=4)
Sort Key: p.id
-> Hash Right Join (cost=257.75..267.76 rows=42 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..8.11 rows=411 width=8)
-> Hash (cost=257.23..257.23 rows=42 width=8)
-> Hash Right Join (cost=129.94..257.23 rows=42 width=8)
Hash Cond: (sc.from_project = epips.project_id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..118.25 rows=1725 width=4)
-> Hash (cost=129.42..129.42 rows=42 width=12)
-> Hash Join (cost=124.34..129.42 rows=42 width=12)
Hash Cond: (eip_1.product_id = p.id)
-> Hash Right Join (cost=25.62..30.59 rows=42 width=12)
Hash Cond: (epips.erp_purchase_inbound_id = epis.id)
-> Seq Scan on tbl_erp_purchase_inbound_projects epips (cost=0.00..3.89 rows=189 width=8)
-> Hash (cost=25.09..25.09 rows=42 width=12)
-> Hash Left Join (cost=10.77..25.09 rows=42 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.21 rows=42 width=32)
Filter: (inventory > '0'::numeric)
-> Hash (cost=8.12..8.12 rows=212 width=4)
-> Seq Scan on tbl_erp_purchase_inbounds epis (cost=0.00..8.12 rows=212 width=4)
-> Hash (cost=72.21..72.21 rows=2121 width=20)
-> Seq Scan on tbl_products p (cost=0.00..72.21 rows=2121 width=20)