MySQL Forums
Forum List  »  Performance

Re: Why is ORDER BY ASC is slow but ORDER DESC is fast ? and how can i fix it ?
Posted by: Rick James
Date: October 05, 2015 10:38AM

Notice that the 'key' it picked was targeted at
ORDER BY comments_count
For ASC vs DESC, probably the desired (re: WHERE) rows were at one end of the table instead of the other. That would explain ASC and DESC having distinctly different times. The Handler numbers confirm it:
| Handler_read_next | 6799069 | versus
| Handler_read_prev | 25635 |

This is a drawback of
WHERE ... ORDER BY ...
and having both
INDEX(tailored for WHERE)
INDEX(tailored for ORDER BY)
The Optimizer tries both, but does not have adequate statistics to always make the right choice.

I dislike "index hints", but this might be warranted in your case:
FROM content IGNORE INDEX(comments_count)

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Why is ORDER BY ASC is slow but ORDER DESC is fast ? and how can i fix it ?
1074
October 05, 2015 10:38AM


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.