MySQL primary key and rule set to index by default

Source: Internet
Author: User

If the MySQL table is Tanki, then the primary key will be indexed by the system default.

If the MySQL table is a composite primary key, the system will follow the left alignment principle, such as composite primary key A and B fields and C fields ..., that only a is indexed by default, B and behind are not indexed, because the A field is before the B field, the index follows the left alignment will only set a default index, the query as   where a=?  or where a=?   and b=? As long as there is a in these 2 query conditions, the A index is used, i.e. a, AB, ABC, a ... An index is used as long as there is a, and b, BC, BD, BCD, CD 、... Conditions as long as there is no index, the query will be very slow, the index either in the condition of a band, or the condition of B or C, etc. also build a separate index.

Note: From the top left to the normalization, we will build the table in the future when the most often used in the condition is placed in the front, so that involves the joint primary key to follow the left alignment principle can be used to index the field by default.

MySQL primary key and rule set to index by default

Related Article

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.