QUERY PLAN
Limit (cost=475.60..475.65 rows=20 width=462)
-> Sort (cost=475.60..480.32 rows=1886 width=462)
Sort Key: p.updated_at DESC
-> HashAggregate (cost=359.41..425.42 rows=1886 width=462)
Group Key: p.id
-> Hash Join (cost=214.91..307.54 rows=1886 width=462)
Hash Cond: (p.id = p_4.id)
-> Hash Left Join (cost=66.76..154.43 rows=1886 width=462)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=37.91..118.47 rows=1886 width=398)
Hash Cond: (p.id = tmp3.product_id)
-> Hash Left Join (cost=17.29..89.07 rows=1886 width=334)
Hash Cond: (p.id = tmp2.product_id)
-> Hash Left Join (cost=1.57..68.39 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.51..1.51 rows=5 width=132)
-> Subquery Scan on tmp1 (cost=1.36..1.51 rows=5 width=132)
-> HashAggregate (cost=1.36..1.46 rows=5 width=164)
Group Key: sub1.product_id
-> Seq Scan on tbl_erp_inventory_products sub1 (cost=0.00..1.13 rows=13 width=18)
-> Hash (cost=15.65..15.65 rows=5 width=68)
-> Subquery Scan on tmp2 (cost=15.53..15.65 rows=5 width=68)
-> HashAggregate (cost=15.53..15.60 rows=5 width=68)
Group Key: e.product_id
-> Hash Left Join (cost=1.29..13.95 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.13..1.13 rows=13 width=8)
-> Seq Scan on tbl_erp_inventory_products e (cost=0.00..1.13 rows=13 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=124.58..124.58 rows=1886 width=4)
-> HashAggregate (cost=86.86..105.72 rows=1886 width=4)
Group Key: p_4.id
-> Hash Left Join (cost=1.29..82.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.13..1.13 rows=13 width=4)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..1.13 rows=13 width=4)