Schema optimization and indexing

Source: Internet
Author: User

An index is a data structure. It can help MySQL get data more efficiently. It's a decisive factor for good performance, but people often forget to use them or don't understand them correctly, so in real-world examples, indexes always cause performance problems. That's why we put the index in the earlier part of the book. Even put the index chapter before the statement optimization.

Indexes (also called keys in MySQL) are especially important when the data is getting bigger. Small amount of data, no high load, in the absence of indexes, the database can also perform well, but as the volume of data, performance degradation is very powerful.

The easiest way to understand the MySQL index is to think about the index of the book. You can easily find what you need through the index of the book. And you can know the page number of the content.

MySQL uses indexes in a similar way. It looks up the index data structure of the value. When it finds a match, it can find the row that contains the match. If you run the statement:

Mysql> SELECT first_name from sakila.actor WHERE actor_id = 5;

There will be an index on the actor_id, so MySQL uses the index to find rows with actor_id 5. In other words, it looks up the value through the index and returns any rows that contain the specified values.

An index contains values from columns or columns that are specified in a table. If you index more than 1 columns, the order of the columns is particularly important. Because MySQL only efficiently searches the index of the leftmost prefix. You will see that it is different to create an index on two columns and create separate indexes for two columns.

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.