"Database"-a field with a value of only 0 and 1, do you want to build an index?

Source: Internet
Author: User

All articles about database indexing will tell you not to Jianjian the word index.

But the fact that these articles will not tell you is:

The index is very useful if the value of this field in the table is extremely uneven, and you need to query for less distributed records.

For example, if there are 10 million records in a table, and a record with a status of 0 will probably have 100, then if you want to query a record with a status of 0, there are no indexes that have a very large impact, and the query status is 1, then the index is basically useless. If the number of records in both states is similar, the index is basically useless.

All of the articles on the index, it is recommended that you do not Jianjian the index of this word, are based on the value distribution is uniform. But if the values are unevenly distributed, the advice is not necessarily correct. The more uneven the value distribution, the more valuable the index is when the records we need to query happen to be less distributed.

The nature of the index is sort, because everyone is lined up, so the same data is sorted in turn. At this time, like the Olympic Games opening the entrance of the athletes, the Chinese team, the United States, Germany ... The captain held up his country's small brand, so that people could see where the Swedish team was (indexed) far away. This time, you have to interview the Swedish team, run directly over the line. When you want to go to the restaurant for a Swedish interview (without an index), you have to ask the past: brother, are you Swedish? When you find the interview object, or forget it, people have finished eating dinner (query timeout) ...

In the case of two values, the image point is that you are looking for someone in the people's Square in Shanghai, to see if you are a Chinese or a foreigner. Finding 10 Chinese is simple, basically catching one. But to find 10 foreigners, it will cost time ... This time if everyone in line, the Chinese platoon in front, the foreigner platoon behind, you can go straight to the end of the team to shout 10 foreigners.

Now it is understood that the index of this field should not be built at all.

Transferred from: https://www.cnblogs.com/xuanbg/p/9473049.html

"Database"-a field with a value of only 0 and 1, do you want to build an index?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.