sqlserver avoids full table scan

Index failure reasons

1: Full value matching
2: Best left prefix rule
3: Primary key insertion order
4: Calculation, function, type conversion (automatic or manual) causes index failure
5: Type conversion causes index failure
6: The column index on the right side of the range condition becomes invalid
7 : Not equal to (!= or <>) Index invalidation
8: is null can use the index, is not null cannot use the index
9: like starts with the wildcard character %, the index
is invalid 10: There are non-indexed columns before and after or, the index is invalid (before and after or) Fields can all have indexes)
11: The character sets of databases and tables use utf8mb4 uniformly. Different character sets need to be converted before comparison, causing index failure. 12
: order by When sorting according to the index, if the selected mapping is not an index, it will not Go through the index. If you sort the primary key, you will still go through the index
13:> If the primary key or index is an integer type, you will still go through the index.

How to optimize?

1: Add dirty reading with (nolock)
2: Add indexes for multiple query conditions
3: Check the index invalid syntax (refer to the reasons for index failure above)
4: Narrow the query scope (such as order plus time statistics)
5: Fields in front of the where condition Try to place conditions that narrow the scope
6: Optimize statements that affect performance

Guess you like

Origin blog.csdn.net/weixin_49543015/article/details/131399355