QUERY PLAN
Subquery Scan on sub (cost=521.47..579.67 rows=10 width=471)
Filter: (sub.id = 1624)
-> WindowAgg (cost=521.47..555.42 rows=1940 width=471)
-> Sort (cost=521.47..526.32 rows=1940 width=463)
Sort Key: sub_1.updated_at DESC
-> Subquery Scan on sub_1 (cost=328.23..415.53 rows=1940 width=463)
-> HashAggregate (cost=328.23..396.13 rows=1940 width=463)
Group Key: p.id
-> Hash Join (cost=180.09..274.88 rows=1940 width=463)
Hash Cond: (p.id = p_4.id)
-> Hash Left Join (cost=26.76..116.45 rows=1940 width=463)
Hash Cond: (p.id = tmp4.product_id)
-> Hash Left Join (cost=24.40..106.76 rows=1940 width=399)
Hash Cond: (p.id = tmp3.product_id)
-> Hash Left Join (cost=20.40..95.01 rows=1940 width=335)
Hash Cond: (p.id = tmp2.product_id)
-> Hash Left Join (cost=10.07..79.57 rows=1940 width=271)
Hash Cond: (p.id = tmp1.product_id)
-> Seq Scan on tbl_products p (cost=0.00..64.40 rows=1940 width=143)
-> Hash (cost=8.85..8.85 rows=97 width=132)
-> Subquery Scan on tmp1 (cost=5.94..8.85 rows=97 width=132)
-> HashAggregate (cost=5.94..7.88 rows=97 width=164)
Group Key: sub1.product_id
-> Seq Scan on tbl_erp_inventory_products sub1 (cost=0.00..4.07 rows=107 width=17)
-> Hash (cost=9.49..9.49 rows=68 width=68)
-> Subquery Scan on tmp2 (cost=7.79..9.49 rows=68 width=68)
-> HashAggregate (cost=7.79..8.81 rows=68 width=68)
Group Key: e.product_id
-> Hash Left Join (cost=5.41..7.28 rows=68 width=14)
Hash Cond: (p_1.erp_inventory_product_id = e.id)
-> Seq Scan on tbl_erp_inventory_product_spents p_1 (cost=0.00..1.68 rows=68 width=14)
-> Hash (cost=4.07..4.07 rows=107 width=8)
-> Seq Scan on tbl_erp_inventory_products e (cost=0.00..4.07 rows=107 width=8)
-> Hash (cost=3.40..3.40 rows=48 width=68)
-> Subquery Scan on tmp3 (cost=2.20..3.40 rows=48 width=68)
-> HashAggregate (cost=2.20..2.92 rows=48 width=104)
Group Key: p_2.product_id
-> Seq Scan on tbl_erp_inventory_start_products p_2 (cost=0.00..1.48 rows=48 width=100)
-> Hash (cost=2.30..2.30 rows=5 width=68)
-> Subquery Scan on tmp4 (cost=2.17..2.30 rows=5 width=68)
-> HashAggregate (cost=2.17..2.25 rows=5 width=72)
Group Key: p_3.product_id
-> Hash Join (cost=1.05..2.12 rows=5 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..1.05 rows=5 width=72)
-> Hash (cost=1.02..1.02 rows=2 width=4)
-> Seq Scan on tbl_erp_inventory_losts e_1 (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_4.id
-> Hash Left Join (cost=5.41..85.43 rows=1940 width=4)
Hash Cond: (p_4.id = eip.product_id)
-> Seq Scan on tbl_products p_4 (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)