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

How to realize sub-database and table in database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article will explain in detail how to achieve sub-database and sub-table in the database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Slicing is a direct way to solve the storage capacity limitation of database. Slicing includes two ways: vertical slicing and horizontal slicing.

Vertical slicing

Vertical slicing is also called vertical segmentation, that is, the original database is divided into multiple databases with logical tables as units. Different tables are stored in different databases after sharding.

Vertical sharding is closely related to business architecture design. For example, the architecture of the system is optimized from the business domain, which is divided into multiple sub-business systems, and the coupling degree of each sub-business system is low. Data communication and data exchange are carried out between sub-business systems in the way of interface.

After the vertical split, the business is clear, the split rules are clear, and the systems are easy to integrate and expand. It is generally used in the design of database upper architecture.

Figure 1 schematic diagram of vertical slicing

Horizontal fragmentation

Horizontal slicing is also called horizontal segmentation, that is, taking the data row records in the logical table as units, the original logical database is divided into multiple physical database slices, and the table data records are distributed and stored on each slice.

Horizontal slicing can not be subdivided mainly by the business architecture, but the amount of data in a single table in the database is too large, and the query performance is degraded. Through horizontal slicing, the problem of single database capacity is solved and the concurrent query performance is improved at the same time.

Fig. 2 horizontal slicing diagram

DDM implements automatic horizontal sharding, so applications don't have to care about which shard a certain data should be stored in.

For logical table horizontal sharding, you need to follow certain sharding rules. For example, in an order tracking system, we select the order number (OrderId) as the split key to split the "order flow table", "order details table" and "logistics tracking table" horizontally. The split rule is to calculate the model after the key value Hash, then the sharding calculation rules are as follows:

H (Key (OrderId)) = Hash (Key (OrderId))% N

Where N indicates that there are a total of N data fragments, and H (Key (OrderId)) represents the part number stored after the order number Hash and modeled.

Figure 3 schematic diagram of data storage after slicing

This is the end of the article on "how to achieve sub-database and sub-table in the database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please 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

Database

Wechat

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

12
Report