Re: Subquery with range uses filesort
Posted by:
Rick James
Date: November 21, 2013 02:55PM
> I'm not actually fetching that column.
SELECT * was your query. It _does_ fetch that column. If you are not actually using "SELECT *", then the EXPLAINs you provided may be bogus, plus much of this thread, may be irrelevant. MySQL does many optimizations. "*" prevents some of them. Please show the actual query.
> The temp table is declared "engine=memory".
There are two types of temp tables -- those that you create explicitly, and those that are implicitly created when it says "using temporary" or "using filesort". It is even possible that a single SELECT can involve more than one implicit temp table.
My discussion of BLOB and MEMORY/MyISAM was referring to the implicit temp table involved "filesort".
> I figured out that the temp table had switched from MyISAM to InnoDB.
New versions of MySQL default to InnoDB (previously MyISAM). You can (should?) always explicitly state the ENGINE when doing CREATE TABLE.
> The results can contain anywhere from one player to 54,106.
And what do you do if there are thousands of players in the output? Show them all? Paginate?
> With InnoDB, updating one row of the temp table took 0.1 second.
Implicit temp tables have no indexes (until ~5.6).
Explicit temp tables have indexes only if you specify them -- and it is often a good idea to do so.
I can't be sure, but perhaps it took as long as 0.1s because of not having a good index.
> I would think the sorting would take a noticeable amount of time.
Yes, sorting takes time. But it is rarely the main cause of slow queries. It can, however, be heavily implicated. Example:
SELECT ... ORDER BY foo LIMIT 10
If it cannot use an index, it will gather _all_ the rows, sort them, and only then count to 10.
If it can use an index, it may be able to read only the 10 desired rows, not touching the rest of the rows.
Subject
Views
Written By
Posted
4455
November 16, 2013 02:42PM
1555
November 17, 2013 07:42PM
1567
November 17, 2013 08:01PM
1581
November 18, 2013 04:33PM
2111
November 18, 2013 07:54PM
1793
November 19, 2013 04:10PM
1678
November 19, 2013 08:36PM
Re: Subquery with range uses filesort
1749
November 21, 2013 02:55PM
1959
December 05, 2013 03:46PM
1587
December 07, 2013 02:10PM
1555
December 09, 2013 06:08PM
1651
December 14, 2013 09:51PM
1522
December 14, 2013 10:17PM
1595
December 15, 2013 11:29PM
1686
December 17, 2013 06:58PM
1604
December 18, 2013 05:49PM
1648
December 18, 2013 08:28PM
1660
December 19, 2013 10:13PM
1635
December 19, 2013 10:28PM
1487
December 20, 2013 07:06PM
1579
December 21, 2013 07:36AM
1624
December 22, 2013 10:01AM
1683
December 22, 2013 10:45AM
1578
December 25, 2013 09:30PM