Mysql table sharding scenario analysis and simple table sharding operations

Source: Internet
Author: User


Table Partitioning can be performed in two ways::

: Place data rows in two independent tables based on the values of one or more columns of data.
Horizontal segmentation usually uses a large table in the following situations. After segmentation, the data to be read and the number of pages of the index can be reduced during query, and the number of layers of the index can be reduced, improves the query speed.
Data in a table is inherently independent. For example, data in different regions or periods is recorded in a table. In particular, some data is often used, while others are not.
Data needs to be stored on multiple media.
Horizontal segmentation increases the complexity of applications. It usually requires multiple table names during query, and all data needs to be queried.

: Put the primary code and some columns in one table, and then put the primary code and other columns in another table.
If some columns in a table are commonly used, but other columns are not commonly used, vertical segmentation can be used. In addition, vertical segmentation can reduce data rows and store more data on one data page, the disadvantage is that redundant columns need to be managed and all data needs to be queried.

The blog's page views, replies, and other similar statistical information, or other frequently-changing data, we call it active data.
Therefore, when designing the database structure, we should consider Table sharding. First, we should deal with vertical table sharding.
After Vertical table sharding:
First, the storage engine is used differently, and the cold data is used. Second, more slave database configuration is performed on the cold data, because more operations are performed on the query, which speeds up the query. For hot data, more Master databases can be used for horizontal table sharding.
In fact, you can also consider using some special active data.

For example, a blog cold data table can be divided

Mysqlhttp: // blog.csdn.net/heirenheiren/article/details/7896546

 show engines  \G;

Create a member table

     auto_increment  (    InnoDB  CHARSETutf8 AUTO_INCREMENT ; 

Step 2: Create a stored procedure and insert millions of data

         i  i  (i    member(name,sex) (concat(,i),i i  i 

      (    MyISAM   CHARSETutf8 AUTO_INCREMENT     tb_member2  tb_member1;

Step 4

    (    MERGE (tb_member1,tb_member2) INSERT_METHODLAST AUTO_INCREMENT ; 

 show   tb_member \G;

Step 5

  member  member.id  member  member.id ;

Step 6

Step 7: 



2. 4. REPLACE5. AUTO_INCREMENT
Create
FIRST

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.