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
MySQL AB, www.mysql.com
My blog: http://s.petrunia.net/blog

Options: ReplyQuote


Subject
Views
Written By
Posted
3215
January 24, 2005 01:27PM
Re: avoid file sort for IN() ORDRE BY
2361
January 24, 2005 11:06PM
1869
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.