Five, MySQL optimization-table vertical Division and horizontal Division

Source: Internet
Author: User
Tags one table

1, the horizontal division of the table

If a table has too many records, such as tens of thousands, and it needs to be retrieved frequently, it is necessary to piecemeal. If I break into 100 tables, then there are only 100,000 records for each table. Of course, the data can be logically divided. A good division basis, in favor of the simple implementation of the program, can also make full use of the advantages of the horizontal table. For example, the system interface only provides monthly query function, then the table by month split into 12, each query query only one table is enough. If you want to divide according to the region, the table can be removed in a small, query or to unite all the tables to check, it is better not to dismantle. So a good basis for splitting is the most important.

such as QQ user information, a single User data table storage card, you can do 100 the same user table, respectively, user_0,user_1,............ user_99, insert a new user, according to k=qqid/100, inserted into the User_k data table.

2, Vertical division of the table

Some table records are not many, may also be 2, 30,000, but the field is very long, the table occupies a large space, the retrieval needs to perform a large number of I/O, severely reducing performance. At this point, you need to split the large field into another table, and the table is a one-to-one relationship with the original table.

For example, the student answer sheet, Student data table field has id,name,score,email,question,answer. Where question and answer data is relatively large, you can separate the two fields, forming a separate table, the data table is divided vertically after the following, Student data table Id,name,score,email. Paper Data Sheet id,stuid,question,answer.

Five, MySQL optimization-table vertical Division and horizontal Division

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.