optimized order by @rid queries