QUERY PLAN
Aggregate (cost=426.77..426.78 rows=1 width=8)
-> Sort (cost=398.48..403.20 rows=1886 width=985)
Sort Key: p.updated_at DESC
-> HashAggregate (cost=277.01..295.87 rows=1886 width=985)
Group Key: p.id
-> Hash Join (cost=189.59..272.30 rows=1886 width=12)
Hash Cond: (p.id = p_3.id)
-> Hash Left Join (cost=46.45..124.19 rows=1886 width=12)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=17.65..88.28 rows=1886 width=12)
Hash Cond: (p.id = tmp3.product_id)
-> Seq Scan on tbl_products p (cost=0.00..61.86 rows=1886 width=12)
-> Hash (cost=15.52..15.52 rows=170 width=4)
-> Subquery Scan on tmp3 (cost=12.12..15.52 rows=170 width=4)
-> HashAggregate (cost=12.12..13.82 rows=170 width=104)
Group Key: p_1.product_id
-> Seq Scan on tbl_erp_inventory_start_products p_1 (cost=0.00..11.70 rows=170 width=4)
-> Hash (cost=28.75..28.75 rows=4 width=4)
-> Subquery Scan on tmp4 (cost=28.65..28.75 rows=4 width=4)
-> GroupAggregate (cost=28.65..28.71 rows=4 width=72)
Group Key: p_2.product_id
-> Sort (cost=28.65..28.66 rows=4 width=4)
Sort Key: p_2.product_id
-> Hash Join (cost=12.65..28.61 rows=4 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..14.70 rows=470 width=8)
-> Hash (cost=12.62..12.62 rows=2 width=4)
-> Seq Scan on tbl_erp_inventory_losts e (cost=0.00..12.62 rows=2 width=4)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=119.57..119.57 rows=1886 width=4)
-> HashAggregate (cost=81.85..100.71 rows=1886 width=4)
Group Key: p_3.id
-> Hash Left Join (cost=1.09..77.14 rows=1886 width=4)
Hash Cond: (p_3.id = eip.product_id)
-> Seq Scan on tbl_products p_3 (cost=0.00..61.86 rows=1886 width=20)
-> Hash (cost=1.04..1.04 rows=4 width=4)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..1.04 rows=4 width=4)