search
HomeCommon ProblemThere are several ways to split a database

There are several ways to split a database

Jun 29, 2020 pm 01:20 PM
database

Database splitting includes: 1. Divide by function [vertical segmentation] and put tables related to different functions into different databases. The advantage of this is that it is very intuitive; 2. According to a certain part of the table Range division of field values ​​[horizontal segmentation]. When the amount of data in a certain table becomes larger and larger and becomes unbearable, it needs to be further segmented.

There are several ways to split a database

Several ways to split the database:

1. Divide by function (vertical segmentation)

Put tables related to different functions into different databases. The advantage of this is that it is very intuitive. But when the data volume or performance requirements of a certain part of the function exceed the controllable range, it needs to be further segmented.

2. Divide according to the range of a certain field value in the table (horizontal segmentation)

When the amount of data accompanying a certain table becomes larger and larger and becomes unbearable, it needs to be Further segmentation. One option is to segment based on the key range, for example, put the IDs 1-10000 on A, and the IDs 10000~20000 on B. Such expansion is foreseeable. The other is to divide according to a certain field value. For example, according to the first letter of the user name, if it is A-D, it belongs to A, and E-H belongs to B. There is also an imbalance in this. When a certain range exceeds the range that a single point can bear, it needs to continue to be divided. There are also segmentation by date and so on.

Advantages: The size of a single table is controllable, and natural horizontal expansion

Disadvantages: The problem of centralized writing bottleneck cannot be solved.

3. Segmentation based on hash

Generally use mod to split. First determine the number of split databases, and decide which one to use by taking the hash modulus. This method can distribute data evenly, but as the amount of data increases, when expansion is needed, this method cannot achieve online expansion. Every time a node is added, the hash algorithm needs to be recalculated.

Therefore, it is recommended to use the consistent hash mod 2^n using this method.

Taking the Dianping Unified Order Database as an example, the solution for sub-database and sub-table is 32*32, that is The last four digits of userId are divided into 32 libraries by mod 32. At the same time, each library is divided into 32 tables by using the last four digits of userId div 32 mod 32, for a total of 1024 tables. Its online deployment is 8 clusters (master-slave), each cluster has 4 libraries

4. Segmentation based on routing table

The previous methods all determine operations based on application data. Segmentation based on routing tables is a more relaxed method. It maintains a separate routing table and searches the routing table to decide which database to use based on a certain attribute of the user. This method is a more general solution.

Advantages: The mapping algorithm of id and library can be changed at will

Disadvantages: Additional single points may be introduced

The above is the detailed content of There are several ways to split a database. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software