Sharding-JDBC sub-database sub-table study notes

What is sub-library and sub-table

        Sub-database sub-table is to solve the problem of database performance degradation due to excessive data volume. The original independent database is split into several databases, and the large data table is split into several data tables, so that a single database, a single data The amount of data in the table becomes smaller, so as to achieve
the purpose of improving the performance of the database.

The way of sub-database sub-table

Sub-database and sub-table include two parts: sub-database and sub-table. In production, it usually includes four ways: vertical sub-warehouse, horizontal sub-warehouse, vertical sub-table, and horizontal sub-table

Vertical table:

The improvements it brings are:

1. In order to avoid 10 contention and reduce the chance of locking the table, users who view details and product information browsing do not affect each other

2. Give full play to the operation efficiency of popular data, and the high efficiency of product information operation will not be dragged down by the low efficiency of product description.

1.1.2 Vertical sub-library

Vertical sub-database is to classify tables according to business and distribute them to different databases. Each database can be placed on different servers. Its core concept is dedicated to special databases.

The improvements it brings are:

•Solve the transition at the business level, and the business is clear

• Able to perform hierarchical management, maintenance, monitoring, expansion, etc. on data of different businesses

• In high concurrency scenarios, the vertical sub-library has been improved to a certain extent by 10, the number of database connections, and the bottleneck of stand-alone hardware resources has been reduced

     The vertical sub-database classifies the tables according to the business, and then distributes them in different databases, and these databases can be deployed on different servers, so as to achieve the effect of multiple servers sharing the pressure, but it still does not solve the problem of excessive data volume in a single table .

1.2.3

Horizontal database partitioning is to split the data of the same table into different databases according to certain rules, and each database can be placed on different servers.

<!--Comparison: Vertical database splitting is to split different tables into different databases. It splits data rows without affecting the table structure -->

The improvements it brings are:
  • Optimize the performance problems caused by the large amount of data in a single table
  • Improved system stability and availability. <! One - Stability is reflected in the reduction of I0 conflicts and locks, availability refers to a problem with a certain library, and part of it is available -->

When an application is difficult to fine-grained vertical segmentation, or the number of rows of data after segmentation is huge, and there is a single database read and write and storage performance bottleneck, then it is necessary to perform horizontal database segmentation. After horizontal segmentation optimization, often It can solve the storage capacity and performance bottlenecks of a single database. However, because the same table is allocated in different databases, additional routing work for data operations is required, which greatly increases the complexity of the system.

1.2.4. Horizontal table

According to the idea of ​​horizontal sub-database, he can also split the tables in PRODUCT_DB_X (commodity library) horizontally, and the purpose is also to solve the large amount of data in a single table.

Horizontal table splitting is to split the data of the same table into multiple tables according to certain rules in the same database.

The improvements it brings are:

Optimize the performance problems caused by the large amount of data in a single table

Avoid IO contention and reduce the chance of locking tables

The horizontal table division in the database solves the problem of excessive data volume in a single table, and the divided small table only contains part of the data, thereby reducing the data volume of a single table and improving retrieval performance.

1.4 Introduction to Sharding-JDBC

We currently only need to focus on Sharding-JDBC, which is positioned as a lightweight Java framework and provides additional services at the JDBC layer of Java. It uses the client to directly connect to the database and provides services in the form of jar packages without additional deployment and dependencies. It can be understood as an enhanced version of the JDBC driver and is fully compatible with JDBC and various ORM frameworks.

2.2.3. Introducing maven dependencies

Introduce the integrated Jar package of sharding-jdbc and SpringBoot:

<dependency>
     <groupId>org.apache.shardingsphere</groupId>
     <artifactId>sharding‐jdbc‐spring‐boot‐starter</artifactId>
     <version>4.0.0‐RC1</version>
   </dependency>

Guess you like

Origin blog.csdn.net/songkai558919/article/details/122788342