MySQL - MySQL index optimization and tips

Index formula

全值匹配我最爱,最左前缀要遵守;

带头大哥不能丢,中间兄弟不能断;

索引列上不计算,范围之后全失效;

LIKE百分写最右,覆盖索引不写 *;

不等空值还有or,索引失效要少用;

字符单引不可丢,SQL高级也不难。

1. Full value matches my favorite

To create several composite index fields, it is best to use only a few fields. And use them in order.

2. Best left prefix principle

The most prefix rule, there must be a front car, and the middle car cannot be broken

3. Do not perform any operation (calculation, function, (automatic/manual) type conversion) on the index column, which will cause the index to fail and perform a full table scan.

4. The storage engine cannot use the columns on the right side of the range condition in the index (all invalid after the range, excluding itself)

If the intermediate index column uses a range (>, <, like, etc.), all subsequent indexes will be invalid.

5. Try to use covering index (try not to use *)

6. Like left fuzzy query will lead to index failure

Sometimes the right fuzzy query can’t find the desired content.
If you want to use % signs on both sides and don’t want the index to fail,
you should use covering query (the query range is within the range of the index that has been established, try to match the index number, in the same order)

use select *

use coverage query

7. is null and is not null will not be able to use the index

8. If the string is not quoted, the index will fail

9. Use or less, as using it to connect may cause index failure.

Guess you like

Origin blog.csdn.net/MinggeQingchun/article/details/130816114