QUERY PLAN
Aggregate (cost=47.56..47.57 rows=1 width=8)
-> Sort (cost=47.55..47.55 rows=1 width=413)
Sort Key: r.updated_at DESC
-> Group (cost=47.53..47.54 rows=1 width=413)
Group Key: r.id
-> Sort (cost=47.53..47.53 rows=1 width=12)
Sort Key: r.id
-> Hash Right Join (cost=34.76..47.52 rows=1 width=12)
Hash Cond: (epop.erp_sales_order_id = r.id)
-> Seq Scan on tbl_erp_sales_order_products epop (cost=0.00..12.00 rows=200 width=8)
-> Hash (cost=34.75..34.75 rows=1 width=12)
-> Hash Right Join (cost=12.26..34.75 rows=1 width=12)
Hash Cond: (rvr.erp_sales_order_id = r.id)
Filter: ((r.created_by = 5016) OR (rvr.user_id = 5016) OR (r.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])))
-> Seq Scan on tbl_erp_sales_order_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=12.25..12.25 rows=1 width=16)
-> Seq Scan on tbl_erp_sales_orders r (cost=0.00..12.25 rows=1 width=16)
Filter: (((NOT outbound_status) OR (NOT is_done)) AND (status = 2))