Mysql condition application or query does not trigger index

Source: Internet
Author: User
Does mysql condition use or query trigger index? The statement is: the where condition contains or and does not use indexes. the test results are as follows: mysql & gt; & nbsp; explain & nbsp; select & nbsp; * & nbsp; from & nbsp; emp & nbsp; where & nbsp; ename = "dsleos" & nbsp; mysql condition use or query will not trigger the index?
The statement is: the where condition contains or and does not use the index.


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: range
possible_keys: e_i
          key: e_i
      key_len: 62
          ref: NULL
         rows: 2
        Extra: Using where
1 row in set (0.00 sec)


If the index is triggered, will or trigger the index? Share :? Explain? Select? *? From? Emp? Where? Ename = "dsleos "? O... 'data-pics = ''>
------ Solution --------------------
Of course, the index will be used.
Of course, if you only test the database because the data volume in the database is not large enough, the Mysql engine may intelligently discard the index and directly query the database.
------ Solution --------------------
Or .)
Related Article

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.