MySQL condition using an OR query does not trigger an index?

Source: Internet
Author: User
The argument is that an or is present in the Where condition and the index is not used


My test results are as follows:
Mysql> explain select * from emp where ename= "Dsleos" or ename= "Saesad" \g*************************** 1. Row ***************************           id:1  select_type:simple        table:emp         type:rangepossible_keys:e_i          key:e_i      key_len:62          ref:null         rows:2        extra:using where1 row in Set (0.00 sec)


The index is triggered, is the use or will not trigger the index AH?


Reply to discussion (solution)

Of course the index is gone.
Of course, if you are just testing, because the data in the database is not large enough, the MySQL engine may intelligently discard the index and query directly.

The fields before or after the or are indexed, so they go indexed (it looks like the results of the MyISAM engine and the InnoDB engine are different. )

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.