A query with a subquery using TOP and ORDER BY on an indexed field returned an incorrect result. It was found that a sort optimization did not properly track that an index could have been used to perform the sort. An optimization routine has been adjusted to take into account all available indexes for proper sort ordering.