MySQL Forums
Forum List  »  Optimizer & Parser

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
4277
November 16, 2013 02:42PM
1497
November 17, 2013 07:42PM
1510
November 17, 2013 08:01PM
1521
November 18, 2013 04:33PM
2051
November 18, 2013 07:54PM
1733
November 19, 2013 04:10PM
1625
November 19, 2013 08:36PM
Re: Subquery with range uses filesort
1684
November 21, 2013 02:55PM
1890
December 05, 2013 03:46PM
1525
December 07, 2013 02:10PM
1501
December 09, 2013 06:08PM
1590
December 14, 2013 09:51PM
1465
December 14, 2013 10:17PM
1534
December 15, 2013 11:29PM
1619
December 17, 2013 06:58PM
1541
December 18, 2013 05:49PM
1583
December 18, 2013 08:28PM
1613
December 19, 2013 10:13PM
1577
December 19, 2013 10:28PM
1435
December 20, 2013 07:06PM
1519
December 21, 2013 07:36AM
1563
December 22, 2013 10:01AM
1627
December 22, 2013 10:45AM
1527
December 25, 2013 09:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.