QUERY PLAN
Aggregate (cost=38.12..38.13 rows=1 width=8)
-> Sort (cost=38.04..38.05 rows=5 width=546)
Sort Key: sub.wrote_date DESC
-> Subquery Scan on sub (cost=37.86..37.98 rows=5 width=546)
-> GroupAggregate (cost=37.86..37.93 rows=5 width=546)
Group Key: r.id
-> Sort (cost=37.86..37.87 rows=5 width=8)
Sort Key: r.id
-> Hash Join (cost=28.34..37.80 rows=5 width=8)
Hash Cond: (r.id = rp.erp_purchase_inbound_id)
-> Seq Scan on tbl_erp_purchase_inbounds r (cost=0.00..7.66 rows=201 width=8)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash (cost=28.28..28.28 rows=5 width=4)
-> Hash Right Join (cost=12.56..28.28 rows=5 width=4)
Hash Cond: (eip.erp_purchase_inbound_product_id = rp.id)
-> Seq Scan on tbl_erp_inventory_products eip (cost=0.00..14.31 rows=531 width=8)
-> Hash (cost=12.50..12.50 rows=5 width=8)
-> Seq Scan on tbl_erp_purchase_inbound_products rp (cost=0.00..12.50 rows=5 width=8)
Filter: (product_id = 2261)