Summary of various situations of 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. The joint index is not null will go as long as the established index column (in no particular order), when in null must be used with the first column of the index, when the first position condition of the index is is null, the other indexes will be established. The column can be is null (but must be null when all columns are satisfied), or = a value; when the first position of the index is = a value, other indexed columns can be any situation (including is null = a value), the index will go in both cases. Other cases will not go.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326265625&siteId=291194637