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

后端 未结 3 2054
春和景丽
春和景丽 2020-11-29 00:57

I\'m working on a event tracking system which uses a handful of lookup tables as well as the primary logging table. In a report I\'m writing, an object can be selected to

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 01:21

    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".

提交回复
热议问题