Mysql sub-database sub-table strategy

1. Horizontal segmentation

Horizontal sharding, also known as the Sharding strategy , splits records in the same table into multiple tables with the same structure.

When the data of a table continues to increase, Sharding is an inevitable choice. It can distribute the data to different nodes of the cluster, thereby caching the pressure of a single database.

Sharding strategy

  • Hash modulo: hash(key) % NUM_DB
  • Range: Can be an ID range or a time range
  • Mapping table: use a separate database to store the mapping relationship

Problems and Solutions of Sharding

1. Business issues

Use distributed transactions to solve, such as XA interface.

2. Links

The original JOIN can be decomposed into multiple single-table queries, and then JOIN can be performed in the user program.

3. ID uniqueness

  • Use globally unique ID: GUID
  • Specify an ID range for each shard
  • Distributed ID generators (like Twitter's Snowflake algorithm)

2. Vertical Slicing

Vertical splitting is to split a table into multiple tables by column, usually according to the degree of relationship density of the columns. Vertical splitting can also be used to split frequently used columns and infrequently used columns into in a different table.

Using vertical segmentation at the database level will deploy to different libraries according to the density of tables in the database, for example, vertically segmenting the original e-commerce database into commodity databases, user databases, etc.

I haven't touched this in my work yet, and I will study it later....

For more information, please refer to:


Copyright belongs to @pdai Original link: https://pdai.tech/md/db/sql-mysql/sql-mysql-devide.html

Guess you like

Origin blog.csdn.net/weixin_70280523/article/details/131713144