MySQL Forums
Forum List  »  Optimizer & Parser

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

Options: ReplyQuote


Subject
Views
Written By
Posted
4420
November 16, 2013 02:42PM
1544
November 17, 2013 07:42PM
1557
November 17, 2013 08:01PM
1571
November 18, 2013 04:33PM
2096
November 18, 2013 07:54PM
1784
November 19, 2013 04:10PM
1668
November 19, 2013 08:36PM
1735
November 21, 2013 02:55PM
1943
December 05, 2013 03:46PM
Re: Subquery with range uses filesort
1576
December 07, 2013 02:10PM
1547
December 09, 2013 06:08PM
1637
December 14, 2013 09:51PM
1510
December 14, 2013 10:17PM
1587
December 15, 2013 11:29PM
1672
December 17, 2013 06:58PM
1590
December 18, 2013 05:49PM
1636
December 18, 2013 08:28PM
1650
December 19, 2013 10:13PM
1627
December 19, 2013 10:28PM
1480
December 20, 2013 07:06PM
1573
December 21, 2013 07:36AM
1611
December 22, 2013 10:01AM
1670
December 22, 2013 10:45AM
1570
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.