Sharding-JDBC core concepts

core concept

After we quoted Sharding-JDBC, our operation of the database seems to be transparent, even if the table becomes three tables in the three databases, our application side will operate with one table when using it. The same feeling. That is to say, the SQL statement in the Mapper mapper of Mybatis does not need to be modified.

Even if the table name of your real table changes, it can automatically generate the name of the real table based on the name of the logical table. Only the original name of the logical table is needed, and Sharing-JDBC will automatically assemble the table name of the real table.

1. Logical table

A general term for tables with the same logic and data structure of a horizontally split database (table). Example: The order data is split into 10 tables according to the mantissa of the primary key, which are t_order_0 to t_order_9, and their logical table is named t_order.

2. Real watch

A physical table that actually exists in a sharded database. That is, t_order_0 to t_order_9 in the previous example.
For example, I divided a user table into three databases, and the user table of each database is a real table.

3. Data node

The smallest unit of data fragmentation. It is composed of data source name and data table, for example: ds_0.t_order_0.
A table in a database is a data node

4. Binding table

Refers to the main table and sub-tables that have consistent fragmentation rules. For example: t_order table and t_order_item table are fragmented according to order_id, then these two tables have a binding table relationship with each other. There will be no Cartesian product association for multi-table association queries between bound tables, and the efficiency of association queries will be greatly improved.

5. Shard key


It is a basis for data fragmentation. For example, if I want to take the modulus, I use the user's primary key to take the modulus, then user_id is the sharding key. If I want to divide the date range into the date, then The date is the shard key and so on.

6. Dynamic table

The name may change

Sharding-JDBC can realize sub-tables without sub-databases, and generate many table names in a database, of course, it can also sub-databases and sub-tables.
A logical table t_order is used in the application,

7. Broadcast table

Some data will be used by various business systems, and multiple cross-database related queries may be required. The broadcast table meets two conditions:

1. Small amount of data
2. Few updates

Put a copy of the same data for all databases or all business systems, so you don't have to rely on a core data

This kind of basic data, or dictionary data table can be set as a broadcast table.

The broadcast table is a redundant idea, and it is also an important means to solve cross-database related queries and avoid cross-database queries.

8. Binding table

For example, the orde table and the order_detail table have a logical primary and foreign key relationship. For example, there is an order_id in the order_detail table, which will correspond to the id of the order table. If the two tables are on different DataNodes, then there is no way to achieve the association. Query.

Guess you like

Origin blog.csdn.net/qq_41489540/article/details/113794362