Using index, using temporary, using filesort – how to fix this?

Well, the doc gives the exact reasons when “Using temporary” will appear:

Temporary tables can be created under conditions such as these:

If there is an ORDER BY clause and a different GROUP BY clause, or if
the ORDER BY or GROUP BY contains columns from tables other than the
first table in the join queue, a temporary table is created.

DISTINCT combined with ORDER BY may require a temporary table.

If you use the SQL_SMALL_RESULT option, MySQL uses an in-memory
temporary table, unless the query also contains elements (described
later) that require on-disk storage.

A quick scan shows that you suffer from #1.

And this blog from 2009 says that “using filesort” means that the sort can’t be performed with an index. Since you’re ordering by a computed field, that’s going to be true, too.

So, that’s what’s “wrong”.

Leave a Comment