Continuous Learning Reference: http://dangdangdotcom.github.io/sharding-jdbc/02-guide/hint-sharding-value/
1, what is the Sub-Library table
Distribute data that belongs to one form to different tables in different databases
2. The concept of the Sub-Library table
Logical tables and Physical tables: T_order are split into T_order_0 and t_order_1, which are called logical tables, which are called physical tables.
Data fragmentation: Consists of a data source name and a data table, such as Db_0.t_order_0
Fragment field: A key field that is used to split a database or table horizontally
Fragmentation algorithm: Determines which data should be routed to which database which table, implemented by the business side, support operations including equal sign, in, Between
SQL Hint: A scenario that is not SQL determined for a fragmented field and is determined by other external conditions, you can use SQL Hint to inject fragmented fields flexibly
3. The problem of the sub-table of the library
(1) Whether to support the fragmentation by multiple fields.
Support
(2) What is a forced route
Definition: Does not depend on the biography in the table into the Piecewise key value
Usage Scenario: The partitioning algorithm determines which library and which table to query for data based on the fragment key value in the following where
For example, select * from T_order where user_id = 1 and order_id = 2
In accordance with USER_ID 2 to determine the target database, order_id 2 determines the target data table, the resulting SQL expression is
SELECT * from db1.t_order_2 where user_id = 1 and order_id = 2
If there is only one field or none, such as SELECT * FROM T_order, select * from T_order where user_id =1
In this case, " if you still want to use the fragmentation policy , you can use the Hint fragment Key Manager
such as a query statement for SELECT * from T_order, set hint to
Hintmanager = Hintmanager.getinstance ();
Hintmanager.adddatabaseshardingvalue ("T_order", "user_id", 1);
Hintmanager.addtableshardingvalue ("T_order", "order_id", 2);
The resulting SQL is a select * from Db1.t_order_0;