MySQL Forums
Forum List  »  Newbie

Re: Slow query. Why is it slow?
Posted by: Phillip Ward
Date: May 20, 2013 09:00AM

Quote

When I remove ORDER BY, it works super fast.
Of course it will.
Without "order by", MySql can simply construct its result set, read through that until it reaches your limit and then stop.
As soon as you add an "order by" clause, MySql is forced to read everything that's relevant (of which there may be a lot; tune your "where" clauses), then sort all of those rows (which is an expensive operation) and only then can it read through the result set until it reaches your limit and stops.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
May 19, 2013 06:35AM
Re: Slow query. Why is it slow?
May 20, 2013 09:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.