QUERY PLAN
Aggregate (cost=19.99..20.00 rows=1 width=8)
-> Sort (cost=19.97..19.98 rows=1 width=546)
Sort Key: sub.wrote_date DESC
-> Subquery Scan on sub (cost=19.94..19.96 rows=1 width=546)
-> GroupAggregate (cost=19.94..19.95 rows=1 width=546)
Group Key: r.id
-> Sort (cost=19.94..19.94 rows=1 width=8)
Sort Key: r.id
-> Nested Loop (cost=0.14..19.93 rows=1 width=8)
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp (cost=0.00..11.68 rows=1 width=8)
Filter: (product_id = 2265)
-> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds r (cost=0.14..8.17 rows=1 width=8)
Index Cond: (id = rp.erp_sales_outbound_id)
Filter: (status = ANY ('{1,2,5}'::integer[]))