Single and multi-column indexes in MySQL database Indexes

Source: Internet
Author: User

The following articles mainly introduce MySQL database indexes, that is, single-column indexes and multi-column indexes, and examples of SQL commands for multi-column indexes, I hope you will have a better understanding of the MySQL database index content after browsing.

To improve search efficiency, we need to consider using multiple MySQL database indexes. If you create a multi-column index for the columns firstname, lastname, and age, MySQL only needs to retrieve the correct results once! The following is an SQL command to create this multi-column index:

 
 
  1. Alter table people add index fname_lname_age (firstname, lastname, age );

Because the index file is saved in B-tree format, MySQL can immediately convert it to the appropriate firstname, then to the appropriate lastname, and finally to the appropriate age. Without scanning any record of the data file, MySQL finds the target record correctly!

So, if you create a single column index on the columns firstname, lastname, and age respectively, will the effect be the same as creating a MySQL database index on multiple columns of firstname, lastname, and age? The answer is no. The two are completely different. When we perform a query, MySQL can only use one index. If you have three single-column MySQL database indexes, MySQL will try to select the most restrictive index.

However, even if it is the most restrictive single-column index, its capacity is certainly far lower than the multiple-column index of the three columns firstname, lastname, and age.

The above content is an introduction to the MySQL database index. I hope you will get something better.

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.