mysql index failure

1) There is no query condition, or the query condition is not indexed 

2) No bootstrap column is used in the query condition 

3) The number of queries is most of the big table, it should be more than 30%. 

4) The index itself is invalid

5) Query conditions use functions on index columns, or perform operations on index columns, operations include (+, -, *, /, !, etc.) Wrong example: select * from test where id-1=9; Correct example : select * from test where id=10; 

6) Querying small tables 

7) Prompt not to use index

8) Statistics are not true 

9) The case where CBO calculates the cost of walking the index is too high. In fact, it also includes the above situation, which means that the block occupied by the table is smaller than the index. 

10) Implicit conversion causes the index to fail. This point should be paid attention to. It is also a mistake that is often made in development. Because the field tu_mdn of the table is defined as varchar2(20), but the field is passed as a number type in a where condition. For Oracle, this will cause the index to fail. Incorrect example: select * from test where tu_mdn=13333333333; Correct example: select * from test where tu_mdn='13333333333'; 

12) 1,<> 2, separate >,<, (sometimes used, sometimes not) 

13,like "%_" percent sign first. 

4, the table is not analyzed. 

15. Separately refer to the index column that is not the first position in the composite index. 

16. When the character field is a number, do not add quotation marks in the where condition. 

17. Operate on the index column. You need to create a functional index. 

18,not in ,not exist. 

19. When the variable uses the times variable and the table field uses the date variable. Or the opposite. 

20, B-tree index is null will not go, is not null will go, bitmap index is null, is not null will go 

21,联合索引 is not null 只要在建立的索引列(不分先后)都会走, in null时 必须要和建立索引第一列一起使用,当建立索引第一位置条件是is null 时,其他建立索引的列可以是is null(但必须在所有列 都满足is null的时候),或者=一个值; 当建立索引的第一位置是=一个值时,其他索引列可以是任何情况(包括is null =一个值),以上两种情况索引都会走。其他情况不会走。

22.如果条件中有or,即使其中有条件带索引也不会使用(这也是为什么尽量少用or的原因)

注意:要想使用or,又想让索引生效,只能将or条件中的每个列都加上索引

23.如果mysql估计使用全表扫描要比使用索引快,则不使用索引

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326887158&siteId=291194637