Horizontal segmentation and vertical segmentation of databases

Source: Internet
Author: User

In database operations, we often hear these two words: horizontal split and vertical split . So what exactly is the horizontal segmentation of the database, and what is the vertical division of the database? In this article, we will introduce this part of the content.

1, Horizontal Division:

Split by record, different records can be saved separately, each child table has the same number of columns.

Horizontal segmentation is typically used in the following situations:

A table is very large, after the partition can reduce the number of data and index to be read at the time of query, and also reduce the index layer, improve the query speed.

The data in table B is inherently independent, for example, in a table where data from each region is recorded or at different times, especially when some data is commonly used, while others are not used.

c The data needs to be stored on multiple media.

For example, the Statute table law can be divided into two tables Active-law and Inactive-law. The contents of the Activea-authors table are laws and regulations that are in force, are often used, while the Inactive-law table makes obsolete regulations less frequently queried. Horizontal partitioning adds complexity to your application, and it usually requires multiple table names at query time, and the union operation is required to query all data. In many database applications, this complexity outweighs its advantages because, as long as the index keyword is not large, when the index is used for querying, the table adds two to three times times the amount of data, and the query increases the number of disks that read an index layer.

2, Vertical Division:

Split by column, saving a record in multiple places, with the same number of rows per child table.

Put the main code and some columns into a table, and then put the main code and other columns in the other table. If some columns in a table are commonly used, while others are not used, vertical segmentation can be used, and vertical partitioning can make the data rows smaller, a data page can hold more data, and the I/O times are reduced at query time. The disadvantage is that redundant columns need to be managed, and the join operation is required to query all data.

For example, a table T1

ID Name Qty

--------------

1 P1 10

2 P2 20

3 P3 30

4 P4 40

......

......

Vertical segmentation is split by column, which saves a record in multiple places, with the same number of rows per child table.

For example, table T1, you can put the ID and name to the data file P1, put qty into the data file P2.

Horizontal segmentation is divided into records, different records can be saved separately, each child table has the same number of columns.

Like the table T1, you can put the ID of the singular to the data file P1, even to the data file P2.

Table hashing is similar to horizontal segmentation, but there is no obvious dividing line like horizontal segmentation, which determines the saved file of a record by the hash function and the key value, so that the IO is more balanced.

About the vertical division of the database and the knowledge of horizontal segmentation is introduced here, I hope this introduction can be a harvest for you!

Http://database.51cto.com/art/201108/282431.htm

Database horizontal split and vertical split difference (MySQL for example) case: The simple shopping system is set up in the following table: 1. Product table (data volume 10w, Stable) 2. Order form (200w of data and growth trend) 3. User table (data volume 100w, And there is a growth trend) with MySQL as an example of the next level split and vertical split, MySQL can tolerate the order of magnitude in millions of static data can go to millions Vertical split: Solve the problem: the IO contention between tables and tables does not solve the problem: the pressure scheme of increasing the amount of data in a single table: placing the Product table and the user table on a server The order table is placed on a single server Horizontal split: Solve the problem: the increase in the amount of data in a single table does not solve the problem: the IO contention between table and table: User table through gender split into male user table and female user form order form completed and completed by split into completed orders and unfinished orders product table Unfinished order placed on a server completed order Form box male user table put a server on a female user table put on a server (woman love shopping haha) c

Horizontal segmentation and vertical segmentation of databases

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.