QUERY PLAN
Aggregate (cost=291.87..291.88 rows=1 width=8)
-> HashAggregate (cost=248.22..267.62 rows=1940 width=985)
Group Key: p.id
-> Hash Join (cost=158.79..243.37 rows=1940 width=4)
Hash Cond: (p.id = p_3.id)
-> Hash Left Join (cost=5.46..84.94 rows=1940 width=4)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=3.16..75.31 rows=1940 width=4)
Hash Cond: (p.id = tmp3.product_id)
-> Seq Scan on tbl_products p (cost=0.00..64.40 rows=1940 width=4)
-> Hash (cost=2.56..2.56 rows=48 width=4)
-> Subquery Scan on tmp3 (cost=1.60..2.56 rows=48 width=4)
-> HashAggregate (cost=1.60..2.08 rows=48 width=104)
Group Key: p_1.product_id
-> Seq Scan on tbl_erp_inventory_start_products p_1 (cost=0.00..1.48 rows=48 width=4)
-> Hash (cost=2.24..2.24 rows=5 width=4)
-> Subquery Scan on tmp4 (cost=2.14..2.24 rows=5 width=4)
-> HashAggregate (cost=2.14..2.19 rows=5 width=72)
Group Key: p_2.product_id
-> Hash Join (cost=1.05..2.12 rows=5 width=4)
Hash Cond: (p_2.erp_inventory_lost_id = e.id)
-> Seq Scan on tbl_erp_inventory_lost_products p_2 (cost=0.00..1.05 rows=5 width=8)
-> Hash (cost=1.02..1.02 rows=2 width=4)
-> Seq Scan on tbl_erp_inventory_losts e (cost=0.00..1.02 rows=2 width=4)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=129.08..129.08 rows=1940 width=4)
-> HashAggregate (cost=90.28..109.68 rows=1940 width=4)
Group Key: p_3.id
-> Hash Left Join (cost=5.41..85.43 rows=1940 width=4)
Hash Cond: (p_3.id = eip.product_id)
-> Seq Scan on tbl_products p_3 (cost=0.00..64.40 rows=1940 width=20)
-> Hash (cost=4.07..4.07 rows=107 width=4)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..4.07 rows=107 width=4)