QUERY PLAN
Limit (cost=28.51..28.52 rows=1 width=457)
-> Sort (cost=28.51..28.52 rows=1 width=457)
Sort Key: r.wrote_date DESC
-> GroupAggregate (cost=28.43..28.49 rows=1 width=457)
Group Key: r.id
-> Sort (cost=28.43..28.44 rows=1 width=148)
Sort Key: r.id
-> Nested Loop (cost=0.55..28.42 rows=1 width=148)
-> Nested Loop Left Join (cost=0.40..20.17 rows=1 width=35)
-> Seq Scan on tbl_erp_sales_outbound_spent_products rp (cost=0.00..11.68 rows=1 width=28)
Filter: (product_id = 2265)
-> Nested Loop Left Join (cost=0.40..8.49 rows=1 width=15)
-> Index Scan using tbl_erp_inventory_products_pkey on tbl_erp_inventory_products eip (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = rp.erp_inventory_product_id)
-> Index Scan using tbl_erp_stores_pkey on tbl_erp_stores s (cost=0.13..0.17 rows=1 width=15)
Index Cond: (eip.erp_store_id = id)
-> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds r (cost=0.14..8.17 rows=1 width=117)
Index Cond: (id = rp.erp_sales_outbound_id)
Filter: (status = ANY ('{1,2,5}'::integer[]))