QUERY PLAN
Aggregate (cost=27.26..27.27 rows=1 width=8)
-> Sort (cost=27.24..27.24 rows=1 width=538)
Sort Key: sub.wrote_date DESC
-> Subquery Scan on sub (cost=27.17..27.23 rows=1 width=538)
-> GroupAggregate (cost=27.17..27.22 rows=1 width=538)
Group Key: r.id
-> Merge Join (cost=27.17..27.21 rows=1 width=8)
Merge Cond: (r.id = rp.erp_sales_return_id)
-> Sort (cost=12.91..12.92 rows=3 width=8)
Sort Key: r.id
-> Seq Scan on tbl_erp_sales_returns r (cost=0.00..12.89 rows=3 width=8)
Filter: (status = ANY ('{1,2,5}'::integer[]))
-> Sort (cost=14.26..14.27 rows=2 width=8)
Sort Key: rp.erp_sales_return_id
-> Seq Scan on tbl_erp_sales_return_products rp (cost=0.00..14.25 rows=2 width=8)
Filter: (product_id = 2105)