Detailed explanation of the concept and application scenarios of sub-database and sub-table

  • Data
    sub-library sub-table concept and application scenarios Detailed
    sub-library sub-table brought some problems
    sharding-jdbc horizontal and vertical sub-library sub-table environment to build
    sharding-jdbc level sub-library sub-table real
    sharding-jdbc sub-library sub-table vertical combat

  • Background
    With the development of the Internet, online businesses have become more and more popular, and the number of users has also increased. This will inevitably lead to an increase in the number of users and increased business pressure. The processing request pressure of the server has been solved by distributed microservices, so the storage The pressure of the layer also needs a solution, so this solution is to sub-database and sub-table.

  • Horizontal sharding of tables
    Insert picture description here
    can alleviate the large data storage, which leads to the problem of slow retrieval even if indexes are used. For example, when mysql has tens of millions of data, the performance of using indexes also begins to decline. At this time, the table is divided, then Each table has only 5 million data, which can solve the index bottleneck problem.

  • Vertical sub
    Insert picture description here
    -tables have two advantages. It can definitely solve the bottleneck of the index, because a b+ tree can store more data, such as pictures, large text data, vertical sub-tables, and there is the concept of master-slave table. This greatly improves retrieval efficiency; concurrent operations can be improved, and the data of two tables can be modified at the same time, which is not limited to row locks.

  • Horizontal sub-database
    Insert picture description here
    Horizontal sub-database is generally not caused by index bottlenecks, but because of the large amount of business concurrency. A database can no longer process all business requests in time, and database requests must be apportioned. If it is not because of the database Can't handle it, the general horizontal sub-table is enough, and the horizontal sub-table is only to solve the index bottleneck problem with a large amount of storage.

  • Vertical sub-databases
    Insert picture description here
    Vertical sub-databases are generally not caused by index bottlenecks, but also caused by large business volume. Generally, a single piece of business is very large, and a database service must be used independently to process it in time. Otherwise, the business volume is not large. , All module business tables can be divided into different schemas.

  • Usage scenario
    Horizontal sub-table: small business concurrency, large single table data, slow data retrieval
    Vertical sub-table: small business concurrency, large table, large text storage
    Horizontal sub-database: large business concurrency, large single table data
    vertical Sub-library: large business concurrency, sub-library of business modules, large business volume per module

  • Summary
    1. If only the amount of data is large and the index bottleneck is reached, then only the table is needed
    . 2. If the amount of data and concurrency are both large, then the io and cpu bottlenecks are reached, then the library needs to be divided.

Guess you like

Origin blog.csdn.net/weixin_38312719/article/details/109011069