| Bug #45828 | Optimizer won't use partial primary key if another index can prevent filesort | ||
|---|---|---|---|
| Submitted: | 29 Jun 17:55 | Modified: | 6 Aug 17:01 |
| Reporter: | Harrison Fisk | ||
| Status: | Closed | ||
| Category: | Server: Optimizer | Severity: | S5 (Performance) |
| Version: | 5.1.35, 5.1.37-bzr, 5.4.0 | OS: | Any |
| Assigned to: | Georgi Kodinov | Target Version: | 5.1+ |
| Tags: | regression, Optimizer, innodb, primary key, order by | ||
| Triage: | Triaged: D2 (Serious) / R3 (Medium) / E3 (Medium) | ||
[29 Jun 17:55]
Harrison Fisk
[29 Jun 18:14]
Valeriy Kravchuk
Note that this bug is InnoDB-specific and it is NOT related to wrong cardinality estimations. So, something is wrong with PRIMARY KEY-related logic in case of InnoDB.
[30 Jun 21:54]
Harrison Fisk
This is a regression that was introduced in 5.1. The behavior was correct in 5.0 and early 5.1 releases. There is no query pattern where this behavior is good, it is not by design. The fact that the behavior is correct if you replace the primary key with a unique or regular index shows that it is incorrect handling of InnoDB primary keys. This is not a feature request. It is a bug (ie. software not working as designed).
[1 Jul 16:34]
Georgi Kodinov
This is an side effect of the fix for bug #28404. Now it unconditionally prefers covering keys over ref access keys (except when the ref access key is also covering).
[3 Jul 12:32]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/77871 2990 Georgi Kodinov 2009-07-03 Bug #36259 (Optimizing with ORDER BY) and bug#45828 (Optimizer won't use partial primary key if another index can prevent filesort The fix for bug #28404 causes the covering indexes to be preferred over non-covering in the following two cases : - when comparing the ordering indexes among themselves - when comparing the ref key to ordering indexes. Fixed by not considering the ordering indexes supperior to the ref key. They're only supperior to non-covering ordering indexes. @ mysql-test/include/mix1.inc Bug #36259: fixed a non-stable test case @ mysql-test/r/innodb_mysql.result Bug #36259 and #45828 : test case @ mysql-test/t/innodb_mysql.test Bug #36259 and #45828 : test case @ sql/sql_select.cc Bug #36259 and #45828 : don't consider covering indexes supperior to ref keys.
[6 Jul 16:56]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/78030 2990 Georgi Kodinov 2009-07-06 Bug #36259 (Optimizing with ORDER BY) and bug#45828 (Optimizer won't use partial primary key if another index can prevent filesort The fix for bug #28404 causes the covering ordering indexes to be preferred unconditionally over non-covering and ref indexes. Fixed by comparing the cost of using a covering index to the cost of using a ref index even for covering ordering indexes. Added an assertion to clarify the condition the local variables should be in. @ mysql-test/include/mix1.inc Bug #36259: fixed a non-stable test case @ mysql-test/r/innodb_mysql.result Bug #36259 and #45828 : test case @ mysql-test/t/innodb_mysql.test Bug #36259 and #45828 : test case @ sql/sql_select.cc Bug #36259 and #45828 : don't consider covering indexes supperior to ref keys.
[7 Jul 14:53]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/78124 2990 Georgi Kodinov 2009-07-07 Bug #36259 (Optimizing with ORDER BY) and bug#45828 (Optimizer won't use partial primary key if another index can prevent filesort The fix for bug #28404 causes the covering ordering indexes to be preferred unconditionally over non-covering and ref indexes. Fixed by comparing the cost of using a covering index to the cost of using a ref index even for covering ordering indexes. Added an assertion to clarify the condition the local variables should be in. @ mysql-test/include/mix1.inc Bug #36259: fixed a non-stable test case @ mysql-test/r/innodb_mysql.result Bug #36259 and #45828 : test case @ mysql-test/t/innodb_mysql.test Bug #36259 and #45828 : test case @ sql/sql_select.cc Bug #36259 and #45828 : don't consider covering indexes supperior to ref keys.
[9 Jul 17:11]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/78293 3017 Georgi Kodinov 2009-07-07 Bug #36259 (Optimizing with ORDER BY) and bug#45828 (Optimizer won't use partial primary key if another index can prevent filesort The fix for bug #28404 causes the covering ordering indexes to be preferred unconditionally over non-covering and ref indexes. Fixed by comparing the cost of using a covering index to the cost of using a ref index even for covering ordering indexes. Added an assertion to clarify the condition the local variables should be in. @ mysql-test/include/mix1.inc Bug #36259: fixed a non-stable test case @ mysql-test/r/innodb_mysql.result Bug #36259 and #45828 : test case @ mysql-test/t/innodb_mysql.test Bug #36259 and #45828 : test case @ sql/sql_select.cc Bug #36259 and #45828 : don't consider covering indexes supperior to ref keys.
[10 Jul 13:21]
Bugs System
Pushed into 5.4.4-alpha (revid:anozdrin@bk-internal.mysql.com-20090710111017-bnh2cau84ug1hvei) (version source revid:joro@sun.com-20090709161101-iov57k1sd3q7kve3) (merge vers: 5.4.4-alpha) (pib:11)
[13 Jul 19:48]
Bugs System
Pushed into 5.1.37 (revid:joro@sun.com-20090713174543-cd2x7q1gi1hzoand) (version source revid:staale.smedseng@sun.com-20090710151930-6e6kq5tp7ux1rtbh) (merge vers: 5.1.37) (pib:11)
[15 Jul 18:10]
Paul DuBois
Noted in 5.1.37, 5.4.4 changelogs. With InnoDB tables, MySQL used a less-selective secondary index to avoid a filesort even if a prefix of the primary key was much more selective.
[27 Jul 18:06]
saravanan krishnarajan
Hi,
I had problem while patching 5.1.36 with sql_select.cc alone.
[root@my_server mysql-5.1.36]# patch -p1 -i bug-46119.patch
patching file mysql-test/include/mix1.inc
patching file mysql-test/r/innodb_mysql.result
patching file mysql-test/t/innodb_mysql.test
patching file sql/sql_select.cc
Hunk #1 succeeded at 13131 with fuzz 2 (offset -1 lines).
Hunk #2 FAILED at 13222.
sql_select.cc.rej:
***************
*** 13214,13220 ****
*/
index_scan_time= select_limit/rec_per_key *
min(rec_per_key, table->file->scan_time());
- if (is_covering ||
(ref_key < 0 && (group || table->force_index)) ||
index_scan_time < read_time)
{
--- 13222,13228 ----
*/
index_scan_time= select_limit/rec_per_key *
min(rec_per_key, table->file->scan_time());
+ if ((ref_key < 0 && is_covering) ||
(ref_key < 0 && (group || table->force_index)) ||
index_scan_time < read_time)
{
[5 Aug 21:57]
James Day
Docs, please add the performance tag to the changelog entry for this bug fix.
[6 Aug 17:01]
Paul DuBois
Done.
[12 Aug 23:47]
Paul DuBois
Noted in 5.4.2 changelog because next 5.4 version will be 5.4.2 and not 5.4.4.
[15 Aug 0:43]
Paul DuBois
Ignore previous comment about 5.4.2.
[26 Aug 15:46]
Bugs System
Pushed into 5.1.37-ndb-7.0.8 (revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[26 Aug 15:46]
Bugs System
Pushed into 5.1.37-ndb-6.3.27 (revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (version source revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (merge vers: 5.1.37-ndb-6.3.27) (pib:11)
[26 Aug 15:48]
Bugs System
Pushed into 5.1.37-ndb-6.2.19 (revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (version source revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (merge vers: 5.1.37-ndb-6.2.19) (pib:11)
[27 Aug 18:33]
Bugs System
Pushed into 5.1.35-ndb-7.1.0 (revid:magnus.blaudd@sun.com-20090827163030-6o3kk6r2oua159hr) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[7 Oct 3:20]
Paul DuBois
The 5.4 fix has been pushed into 5.4.2.
