QUERY PLAN
Aggregate (cost=434.42..434.43 rows=1 width=8)
-> Sort (cost=406.13..410.84 rows=1886 width=985)
Sort Key: p.updated_at DESC
-> HashAggregate (cost=284.66..303.52 rows=1886 width=985)
Group Key: p.id
-> Hash Join (cost=197.24..279.95 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=127.22..127.22 rows=1886 width=4)
-> HashAggregate (cost=89.50..108.36 rows=1886 width=4)
Group Key: p_3.id
-> Hash Left Join (cost=14.05..84.78 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=11.80..11.80 rows=180 width=4)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..11.80 rows=180 width=4)