MySQL Forums
Forum List  »  Optimizer & Parser

How to optimise a query to avoid filesort on LARGE resultset
Posted by: Marek Narkiewicz
Date: November 26, 2007 10:54AM

Hi there. I have the following query:

SELECT whenadded
FROM LogAllEvents
WHERE kioskid=x
ORDER BY whenadded DESC
LIMIT 1

And the following relevant indexes:

UNIQUE KEY `localid` (`localid`,`kioskid`,`whenoccured`,`category`),
KEY `whenadded` (`whenadded`),
KEY `kioskid` (`kioskid`)

By my understanding that should avoid filesort but the problem (I think) is that the table is 19 million records or more, and the result set can be 20 thousand or more.

EXPLAIN gives me:
possible_keys: kioskid
key: kioskid
Extra: Using where; Using filesort

Is there any way to handle this sort in memory or is my query set up wrong? I have 10mb in my sort_buffer and 800mb in my key buffer.

Many thanks.
Maz

Options: ReplyQuote


Subject
Views
Written By
Posted
How to optimise a query to avoid filesort on LARGE resultset
5435
November 26, 2007 10:54AM


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.