Daily Study Notes (15) _ MySQL

Source: Internet
Author: User
Daily Study Notes (15) today I will continue to read the index section in Chapter 1 of MySQL Technology Insider InnoDB storage engine.

When should I use B + tree indexes? Not all columns that appear under all query conditions need to be indexed. The author points out that when a few rows in the table are accessed, using B + tree indexes makes sense. For fields such as gender, region, and type, their optional values are small, that is, low selectivity. for example, Select * from student where sex = 'M ', the result may be 50% of the table's data. adding a B + tree index is completely unnecessary. On the contrary, if a field has a wide range of values and has almost no repeatability, it is highly selective, in this case, using the B + tree index is the most suitable, for example, the name field.

Therefore, when you access a highly selective field and retrieve a small portion of the data from the table, it is necessary to add a B + tree index to this field. However, if the access field is highly selective, but the retrieved row data occupies most of the data in the table, MySQL will not use the B + tree index. The MySQL Optimizer predicts the possible rows to be queried through the EXPLAIN rows field. if the value is greater than a certain value, the B + tree will scan the entire table. As for this value, the author estimates that it is generally 20%, that is, if the retrieved data volume exceeds 20% of the data in the table, the optimizer will not use the index, but scan the entire table. However, sometimes the optimizer is not completely correct, and you can use the index forcibly.

Author: Dongting Sangren

Source: http://phinecos.cnblogs.com/

This blog follows Creative Commons Attribution 3.0 LicenseIf it is used for non-commercial purposes, you can reprint it freely, but please keep the original author information and the article URL.

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.