Home » Performance » MySQL » GROUP BY with ORDER BY without using filesort/tmp table
GROUP BY with ORDER BY without using filesort/tmp table [message #682] Wed, 07 February 2007 14:10 Go to next message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Hi,

No matter what I do, I cannot get this query NOT to use filesort/tmp table.

SELECT ... FROM messages WHERE author=1 AND flag=0 GROUP BY checksum, recipient ORDER BY timestamp DESC LIMIT 10;

Is it possible to get this query to use INDEX/WHERE only?

The index is on:
INDEX(author, flag, checksum, recipient, timestamp)


Martin Gallagher | Speeple: The latest news
Re: GROUP BY with ORDER BY without using filesort/tmp table [message #688 is a reply to message #682 ] Thu, 08 February 2007 05:57 Go to previous messageGo to next message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Not really, because you do group by one set of columns and sort groups by unrelated column.

Think how would you execute such query without using temporary table and file sort ? If you do not see obvious way MySQL quite likely can't do anything ether.

Note your query is also possibly wrong as you sort by timestamp but not all iterms in the group may have same timestamp.


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Re: GROUP BY with ORDER BY without using filesort/tmp table [message #690 is a reply to message #688 ] Thu, 08 February 2007 06:47 Go to previous message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Thanks Peter, I thought that was the case!


Martin Gallagher | Speeple: The latest news
Previous Topic:Advice on server layout
Next Topic:Join tables across database
Goto Forum:
  


Current Time: Sun Jul 5 15:53:07 EDT 2009

Total time taken to generate the page: 0.01036 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.