The index defined in the database table does not take effect

In daily development, I often encounter this problem. Obviously, I have defined the index, and there is no problem in checking the execution plan in the development environment, test environment, and quasi-production environment, but it is invalid when it is in the production environment. No improvement at all.

Why?

Superficial phenomenon: The production environment database is different from the other three environments, so there is this problem. Even if quasi-production is close to the production environment, unless the database is synchronized in real time or the production database is synchronized frequently and regularly, it is still different.

In-depth: Why the same table, the same index, but the problem of the amount of data, lead to different execution plans of the same query statement? One walks the index, and the speed is fast. The other does not walk the index, slow as a snail?

Conclusion: The column where the index is located, or the column where the combined index is located, there is a problem with the data distribution, which causes the database algorithm to think that using the index is not as good as using other execution plans.

This is a common problem. Many database design specifications state that the index should be added in a suitable position. For example, in a large table with 100 million records, you put the index on the IsDelete field, and this field has only two values. 0 or 1, what is the use?

 

おすすめ

転載: blog.csdn.net/airingyuan/article/details/105575281