Mysql Index failure scenarios

For example: USER table has a field attribute name, age wherein the index name

Here are a few cases of failure index

1. select * from USER where name=‘xzz’ or age=16;

For example this situation: When the statement or even with the index will fail.

2.select *  from  USER where name like‘%xzz’ ;

For example this situation: When the index statement like band% failure index (Note: If the sentence is like'xzz 'at this time is in effect index) 

3.select * from USER where name = 123; (to be simply illustrative example, does not name the actual scene typically is digital)

For example this situation: If the column type is a string, it must be used in quotes in the data conditions, or without using an index

 

4. If mysql estimated using the full table scan faster than using the index, an index is not used (this example does not know how the child)

 

5. If the above set name and age joint index, must pay attention to the order, mysql joint so there leftmost principle below as name, age of the order of speaking

(1)select * from USER where name=‘xzz’ and age =11;

(2)select * from USER where age=11 and name=‘xzz’;

Appeal for example, two cases: the name, age joint index order, (1) the index is in effect, (2) failure index is

 

6. For example age index: select * from USER where age-1> 11;

For example this situation: the index fail, do not operate on the index, otherwise the index will fail (there is a problem similar conversion time and the same issue on
appeal) ----------------
Copyright : this article is CSDN blogger "programmer _ king or bronze 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_27101653/article/details/81296988

Guess you like

Origin www.cnblogs.com/aligege/p/11593929.html