Re: Subquery with range uses filesort
Posted by:
Rick James
Date: December 07, 2013 02:10PM
> 1,SIMPLE,Player,ALL,PRIMARY,NULL,NULL,NULL,53985,19.23,"Using where"
> The three dots are really a list of 10384 player IDs.
Note that ~20% of the table is needed. Hence it is reasonable for the optimizer to punt on using the index, and simply do a "table scan".
> For each $PlayerID, it does
> | select HistoryEvent, HistoryDate, HistoryFinalMean,
> ...
> Here is a single query that does the same thing
Good, it should be done in a single step.
> where HistoryPlayer = PlayerID and HistoryDate <= '2012-06-30'
> order by HistoryDate desc, HistoryDirector desc limit 0,1 )
> 2,"DEPENDENT SUBQUERY",History,ref, PlayerDateDirector,PlayerDateDirector,4, ratingscentral.Player.PlayerID,8808,100.00, "Using where; Using filesort"
> PRIMARY KEY (`HistoryEvent`,`HistoryPlayer`),
> UNIQUE KEY `PlayerDateDirector` (`HistoryPlayer`, `HistoryDate`, `HistoryDirector`),
This involves a tricky optimization to make use of that KEY such that it reads only one row. The EXPLAIN implies that it is failing to do that that optimization. Suggest you file a bug at bugs.mysql.com, and focus on the optimization of this subquery. Point out that it could/should say "Using index" instead of "Using where; Using filesort". Also note that `HistoryEvent` is the only other thing in the SELECT, and that is part of the PRIMARY KEY, which is implicitly part of the secondary key mentioned.
Never mind -- don't file a bug report. You will get no sympathy since you are not using InnoDB. If particular, what I said about the PK (above) applies only to InnoDB. Switching to InnoDB may help performance right away!
In MyISAM, you could try adding
INDEX(`HistoryPlayer`, `HistoryDate`, `HistoryDirector`, `HistoryEvent`)
This might get it to "Using index" and maybe optimizing away from scanning ~8808 rows to find the latest one.
> Duration / Fetch
> 0.764 sec / 2.387 sec
What do you mean by "Duration" and "Fetch"?
Subject
Views
Written By
Posted
5004
November 16, 2013 02:42PM
1766
November 17, 2013 07:42PM
1943
November 17, 2013 08:01PM
1799
November 18, 2013 04:33PM
2340
November 18, 2013 07:54PM
2019
November 19, 2013 04:10PM
1929
November 19, 2013 08:36PM
2063
November 21, 2013 02:55PM
2187
December 05, 2013 03:46PM
Re: Subquery with range uses filesort
1860
December 07, 2013 02:10PM
1738
December 09, 2013 06:08PM
1907
December 14, 2013 09:51PM
1739
December 14, 2013 10:17PM
1944
December 15, 2013 11:29PM
2059
December 17, 2013 06:58PM
1823
December 18, 2013 05:49PM
1898
December 18, 2013 08:28PM
1907
December 19, 2013 10:13PM
1856
December 19, 2013 10:28PM
1687
December 20, 2013 07:06PM
1816
December 21, 2013 07:36AM
1983
December 22, 2013 10:01AM
1894
December 22, 2013 10:45AM
1809
December 25, 2013 09:30PM