QUERY PLAN
Limit (cost=469.82..469.87 rows=20 width=462)
-> Sort (cost=469.82..474.54 rows=1886 width=462)
Sort Key: p.updated_at DESC
-> HashAggregate (cost=353.63..419.64 rows=1886 width=462)
Group Key: p.id
-> Hash Join (cost=209.13..301.76 rows=1886 width=462)
Hash Cond: (p.id = p_4.id)
-> Hash Left Join (cost=65.99..153.66 rows=1886 width=462)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=37.14..117.70 rows=1886 width=398)
Hash Cond: (p.id = tmp3.product_id)
-> Hash Left Join (cost=16.52..88.30 rows=1886 width=334)
Hash Cond: (p.id = tmp2.product_id)
-> Hash Left Join (cost=1.15..67.97 rows=1886 width=270)
Hash Cond: (p.id = tmp1.product_id)
-> Seq Scan on tbl_products p (cost=0.00..61.86 rows=1886 width=142)
-> Hash (cost=1.14..1.14 rows=1 width=132)
-> Subquery Scan on tmp1 (cost=1.11..1.14 rows=1 width=132)
-> HashAggregate (cost=1.11..1.13 rows=1 width=164)
Group Key: sub1.product_id
-> Seq Scan on tbl_erp_inventory_products sub1 (cost=0.00..1.04 rows=4 width=21)
-> Hash (cost=15.35..15.35 rows=1 width=68)
-> Subquery Scan on tmp2 (cost=15.33..15.35 rows=1 width=68)
-> HashAggregate (cost=15.33..15.34 rows=1 width=68)
Group Key: e.product_id
-> Hash Left Join (cost=1.09..13.75 rows=210 width=68)
Hash Cond: (p_1.erp_inventory_product_id = e.id)
-> Seq Scan on tbl_erp_inventory_product_spents p_1 (cost=0.00..12.10 rows=210 width=68)
-> Hash (cost=1.04..1.04 rows=4 width=8)
-> Seq Scan on tbl_erp_inventory_products e (cost=0.00..1.04 rows=4 width=8)
-> Hash (cost=18.50..18.50 rows=170 width=68)
-> Subquery Scan on tmp3 (cost=14.25..18.50 rows=170 width=68)
-> HashAggregate (cost=14.25..16.80 rows=170 width=104)
Group Key: p_2.product_id
-> Seq Scan on tbl_erp_inventory_start_products p_2 (cost=0.00..11.70 rows=170 width=100)
-> Hash (cost=28.80..28.80 rows=4 width=68)
-> Subquery Scan on tmp4 (cost=28.65..28.80 rows=4 width=68)
-> GroupAggregate (cost=28.65..28.76 rows=4 width=72)
Group Key: p_3.product_id
-> Sort (cost=28.65..28.66 rows=4 width=68)
Sort Key: p_3.product_id
-> Hash Join (cost=12.65..28.61 rows=4 width=68)
Hash Cond: (p_3.erp_inventory_lost_id = e_1.id)
-> Seq Scan on tbl_erp_inventory_lost_products p_3 (cost=0.00..14.70 rows=470 width=72)
-> Hash (cost=12.62..12.62 rows=2 width=4)
-> Seq Scan on tbl_erp_inventory_losts e_1 (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_4.id
-> Hash Left Join (cost=1.09..77.14 rows=1886 width=4)
Hash Cond: (p_4.id = eip.product_id)
-> Seq Scan on tbl_products p_4 (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)