QUERY PLAN
Subquery Scan on sub (cost=222.18..278.76 rows=9 width=150)
Filter: (sub.id = 947)
-> WindowAgg (cost=222.18..255.18 rows=1886 width=150)
-> Sort (cost=222.18..226.89 rows=1886 width=142)
Sort Key: sub_1.updated_at DESC
-> Subquery Scan on sub_1 (cost=81.85..119.57 rows=1886 width=142)
-> HashAggregate (cost=81.85..100.71 rows=1886 width=142)
Group Key: p.id
-> Hash Left Join (cost=1.09..77.14 rows=1886 width=142)
Hash Cond: (p.id = eip.product_id)
-> Seq Scan on tbl_products p (cost=0.00..61.86 rows=1886 width=142)
-> 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)