MySQL Forums
Forum List  »  Performance

Re: avoid file sort for IN() ORDRE BY
Posted by: Sergey Petrunya
Date: January 24, 2005 11:06PM

MySQL is able to avoid using filesort if requested ordering is "compatible" with ordering produced by the index.
For the first query the ordering is compatible, because for all returned rows index_part_1=1 and so using
"... ORDER BY index_part_2"
has the same effect as
"ORDER BY index_part_1 DESC, index_part_2 DESC".

For the second query index_part_1 is not constant so MySQL has to use filesort. If the number after LIMIT is low and you're willing to go some lengths to avoid using filesort for the second query you could rewrite it as a 4-way UNION with ORDER BY.. LIMIT for each member and for entire UNION.

Sergey Petrunia, Software Developer
My blog:

Options: ReplyQuote

Written By
January 24, 2005 01:27PM
Re: avoid file sort for IN() ORDRE BY
January 24, 2005 11:06PM
January 30, 2005 06:41AM

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.