Data Sub-table sharding JDBC Learning

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.