1

Is there anyother alternative for order by varchar clause? At worst case consider I want to order by varchar column that is not indexed. When I tested a query with loads of data it took many times to execute. It is obvious that it will take much time. But is there any other alternative approach for this without indexing that column?

  • Maybe there's a way to solve the underlying problem another way. Why can't you index the column? Or why don't you want to index it? What permissions do you have on this database and table? – Valerie Parham-Thompson Jun 9 '16 at 2:36
3

Nope. If you order by a not indexed column then the server HAS to load all the results into memory and can only then start sorting them. That is heavy - not sure how mySql does it, but on SqlServer that will also tax the tempdb for the temporary holding of the data. If it is a lot of data that may be super slow due to memory flowing over onto the hard disc.

Physics and logic can not be cheated, sadly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.