Database courses (05) -MyCat sub-library sub-table strategy

1.MyCat sub-library sub-table

Principles for the database sub-sub-table to follow the vertical resolution and horizontal resolution .

1.1 Vertical Split

Vertical split is based on different business, is divided into different databases , such as membership database, order database, database and other payments, vertical split with major electricity supplier system is very common.

advantage:

  • After the demerger clear split rules are clear, easy to integrate or extend between systems.

Disadvantages:

  • Part of the business table can not join, can only be resolved by way of an interface, increases the complexity of the system.
  • There is distributed transaction issues.

1.2 Split Horizontal

Vertical resolution is to split into different tables of different databases, and the horizontal resolution is to split the same table to a different database .

Relative to the vertical split, horizontal split data tables do not classified, but according to certain rules of a field is dispersed into a plurality of banks, each table contains part of the data.

In simple terms, we can cut the level of the data points are understood to be in accordance with the data line segmentation, is to cut some of the rows in the table assigned to a database, while the other cut some lines and assigned to other databases The main partakers table, sub-library mode. The level of segmentation to improve the stability with the load capacity of the system, but the poor performance of cross-database join.

2.MyCat achieve the level of fragmentation strategy

MyCat supports 10 kinds of partitioning strategy

  • Modulo arithmetic
  • Fragmentation enumeration
  • The agreed scope
  • Date specified
  • Fixing the hash algorithm fragment
  • Wild modulo
  • ASCII code modulo wildcard
  • Programming designated
  • Analytical hash string into

Details Reference: http://www.mycat.io/document/mycat-definitive-guide.pdf

2.1 Case

This enumeration fragmentation rules apply to a specific scene, for example, some provinces or districts according to business needs to do to save, counties and provinces nationwide fixed, use this type of business rule. Configuration is as follows:

1. Case steps:

  • Create a database userdb_1, userdb_2, userdb_3

2. Modify the partition-hash-int.txt rules

= 0 Wuhan
Shanghai. 1 =
Suzhou = 2

3. Hubei sub-library database by region, Jiangsu, Shandong database database.

4. The method seeking to touch fragments decimal touch operation request, the operation results in accordance with the partition index id.

Note: The number of fragments database node can not be changed. And ES cluster very similar. The figure is schematic ES cluster, the database of the fragment ( modulo arithmetic ) similar to the ES document sub-library, the details can refer to blog before I wrote "Distributed tutorial series (36) -ElasticSearch cluster principle."
Here Insert Picture Description

Released 2618 original articles · won praise 4883 · Views 390,000 +

Guess you like

Origin blog.csdn.net/qq_20042935/article/details/103660337