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
4507
November 16, 2013 02:42PM
1568
November 17, 2013 07:42PM
1581
November 17, 2013 08:01PM
1593
November 18, 2013 04:33PM
2126
November 18, 2013 07:54PM
1807
November 19, 2013 04:10PM
1687
November 19, 2013 08:36PM
Re: Subquery with range uses filesort
1768
November 21, 2013 02:55PM
1968
December 05, 2013 03:46PM
1596
December 07, 2013 02:10PM
1561
December 09, 2013 06:08PM
1663
December 14, 2013 09:51PM
1529
December 14, 2013 10:17PM
1605
December 15, 2013 11:29PM
1695
December 17, 2013 06:58PM
1613
December 18, 2013 05:49PM
1654
December 18, 2013 08:28PM
1671
December 19, 2013 10:13PM
1646
December 19, 2013 10:28PM
1496
December 20, 2013 07:06PM
1587
December 21, 2013 07:36AM
1630
December 22, 2013 10:01AM
1698
December 22, 2013 10:45AM
1586
December 25, 2013 09:30PM