preface

The content of the service company recently doing split, because the service separation brings the database split, single table data at the same time the company business has reached the highest level, so consider depots table to split on library So the depots table on the agenda is imperative Hereby the study of depots table

What is meant by

Sub-library sub-table, literally means to give a person a feeling of handicraft since it is a handicraft, then of course we have to start from the posture (manual chicken)

vertical

  • Vertical split table: The large table is divided into small tables. The large table has many fields, but these fields are not commonly used in some simple queries. Therefore, it can be divided into basic information tables and details tables.
  • Vertical branch library: the large library is divided into small libraries, generally according to the service to be split, such as order library, user library.

The level of

  • Horizontal split table: Split the row data of the table, such as table ORDER_1 with even primary keys and table ORDER_2 with odd primary keys
  • Horizontal partitioning: Similar to the logic of horizontal partitioning, data is distributed among different libraries according to certain rules

When you need

In a company’s architecture, the database, as the lowest level of infrastructure, provides data service support for various upper-layer applications. Therefore, the performance of the entire architecture may become a bottleneck. Common problems are as follows:

  1. Too many database connections
  2. Queries optimized by indexes cannot meet daily queries
  3. Read/write separation cannot be satisfied

Pay attention to the point

  1. How to handle transactions after repository separation
  2. Multi-data Source Management
  3. The cross-library join operation

How to implement the

  1. ShardingSphere
  2. MyCat

conclusion

  1. Be careful before you divide the database and table, because data changes are involved and business code may need to be changed
  2. In general, the priority of sub-database sub-table is after all optimization schemes. After optimization schemes such as index or read-write separation cannot be satisfied, if these methods cannot fundamentally solve the problem, the sub-database sub-table is carried out
  3. At the beginning of the database design, it is considered to divide the database into tables, but it is not recommended to divide the database into tables directly, most of the products are still to meet the function and use as the premise, and advance divide the database into tables will undoubtedly increase the development cost

This article is published by OpenWrite, a blogging tool platform