Bug #88786 | Optimzer choose wrong index | ||
---|---|---|---|
Submitted: | 6 Dec 2017 13:31 | Modified: | 13 Apr 2018 3:59 |
Reporter: | Olivier ORLANDO | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.7 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | alias, Optimizer, wrong index |
[6 Dec 2017 13:31]
Olivier ORLANDO
[6 Dec 2017 13:33]
Olivier ORLANDO
Contain 2 tables in order to play queries
Attachment: Dump20171206-1.zip (application/zip, text), 2.62 MiB.
[8 Dec 2017 14:01]
MySQL Verification Team
Hi! I have tested your test case and you are indeed right. The plan with FORCE INDEX is much better. Without FORCE INDEX: +----+-------------+-------------+------------+------+--------------------------------------+------------------------------+---------+--------------------+------+----------+----------------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------------+------------+------+--------------------------------------+------------------------------+---------+--------------------+------+----------+----------------------------------------------+ | 1 | SIMPLE | container2_ | NULL | ref | PRIMARY,FK_87sftj2k6a1bucnj5ab2rs4s3 | FK_87sftj2k6a1bucnj5ab2rs4s3 | 9 | const | 2198 | 100.00 | Using index; Using temporary; Using filesort | | 1 | SIMPLE | container1_ | NULL | ref | PRIMARY,FK_87sftj2k6a1bucnj5ab2rs4s3 | FK_87sftj2k6a1bucnj5ab2rs4s3 | 9 | bug.container2_.id | 5 | 100.00 | NULL | | 1 | SIMPLE | content0_ | NULL | ref | FK_gmhpacw2qahxt0gvpvc7243sc | FK_gmhpacw2qahxt0gvpvc7243sc | 9 | bug.container1_.id | 1 | 100.00 | Using index | +----+-------------+-------------+------------+------+--------------------------------------+------------------------------+---------+--------------------+------+----------+----------------------------------------------+ With FORCE INDEX: +----+-------------+-------------+------------+--------+--------------------------------------+------------------------------+---------+---------------------------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------------+------------+--------+--------------------------------------+------------------------------+---------+---------------------------+------+----------+-------------+ | 1 | SIMPLE | container1_ | NULL | index | NULL | IDX_CONTAINER_CREATIONDATE | 6 | NULL | 119 | 100.00 | Using where | | 1 | SIMPLE | container2_ | NULL | eq_ref | PRIMARY,FK_87sftj2k6a1bucnj5ab2rs4s3 | PRIMARY | 8 | bug.container1_.parent_id | 1 | 5.00 | Using where | | 1 | SIMPLE | content0_ | NULL | ref | FK_gmhpacw2qahxt0gvpvc7243sc | FK_gmhpacw2qahxt0gvpvc7243sc | 9 | bug.container1_.id | 1 | 100.00 | Using index | +----+-------------+-------------+------------+--------+--------------------------------------+------------------------------+---------+---------------------------+------+----------+-------------+ Verified as reported.
[13 Apr 2018 3:59]
Erlend Dahl
Duplicate of Bug#83323 Optimizer chooses wrong plan when joining 2 tables