Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are several ways to split the database?

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces you what are several ways of splitting the database, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Several ways to split the database:

1. Divided by function (vertical segmentation)

The advantage of putting tables related to different functions in different databases is very intuitive. However, when the amount of data or performance requirements of a certain part of the function is beyond the controllable range, it needs to continue to be further re-segmented.

2. Divide by range of field values in the table (horizontal segmentation)

When the amount of data in a table becomes too large to bear, it needs to be further segmented. One option is to split according to the range of key, for example, if the ID is 1-10000, put it on A, and put on B if the ID is 10000-20000. Such an expansion is predictable. The other is to divide it according to the value of a certain field, for example, according to the initials of the user name, if it is Amurd, it belongs to Amai D, and Emurh belongs to B. There is also an imbalance in doing so, and when a range is beyond what a single point can bear, it needs to continue to be segmented. And slicing by date and so on.

Advantages: single table size can be controlled, natural horizontal expansion

Disadvantages: unable to solve the bottleneck of centralized writing

3. Segmentation based on hash

Mod is generally used to split, at the beginning to determine the number of database segmentation, through the hash module to decide which one to use. This method can distribute data evenly, but with the increase of the amount of data, when it needs to be expanded, this method can not achieve online expansion. Every time the nodes are added, the hash algorithm needs to be recalculated.

Therefore, using this method, the consistent hash of mod 2 ^ n is recommended.

Taking the unified order library of review as an example, the scheme of sub-database and sub-table is 3232, that is, it is divided into 32 libraries through the last four bits of mod 32 in userId, and each database is divided into 32 tables by div 32 mod 32 in the last four bits of userId, with a total of 1024 tables. Its online deployment is 8 clusters (master-slave), and each cluster has 4 libraries.

4. Segmentation based on routing table

The previous methods determine the operation according to the applied data, and the segmentation based on the routing table is a more loose method. It maintains a separate routing table and looks up the routing table according to a certain attribute of the user to decide which database to use. This is a more general scheme.

Pros: mapping algorithms for id and libraries can be changed at will

Cons: additional single points may be introduced

On the database split several ways are shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report