Bug #68919 | Performance regression when DS-MRR is used for query with small limit | ||
---|---|---|---|
Submitted: | 10 Apr 2013 14:25 | Modified: | 10 Apr 2013 14:27 |
Reporter: | Olav Sandstå | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 5.6.10 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[10 Apr 2013 14:25]
Olav Sandstå
[11 Apr 2013 6:06]
Olav Sandstå
Workaround for for getting back to the 5.5 behavior and performance is to disable use of DS-MRR. This can be done by setting: optimizer_switch="mrr=off";
[12 Apr 2013 12:23]
Olav Sandstå
The reason DS-MRR is used for this query is: 1. When the optimizer evaluates alternative access methods and make cost estimate for each, the "LIMIT 1" is not taken into account. One of the access methods that is considered is to do range access on the seonday index. A range scan can either be done as a "standard range scan" (using the default MRR implementation) or as a "DS-MRR scan". In this case the MRR cost model is given an estimate of almost 10 million records to be read. Based on this, the MRR cost model chooses to use DS-MRR for this range access. 2. After the join optimizer has been run, the optimizer consideres the "LIMIT 1" clause to see if it can use a particular index that likely will require reading only a few records to satisfy the LIMIT 1. And in this case it sees that it already has selected a good index for this. At fails to notice that the selected range access method for this indes is DS-MRR which is not a good access method for satisfying the "LIMIT 1" (since DS-MRR will try to read a lot of index entries into its sort buffer before returning the first result record). Two alternative ideas for how to fix this: a) Take the limit clause into account when estimating the number of records to be read. Use this as input to the MRR cost model. b) When reconsidering which access method to be used for "LIMIT 1", disable use of DS-MRR for the range scan.