当前位置:网站首页>Database storage - table partition
Database storage - table partition
2022-07-07 08:43:00 【Blue sky ⊙ white clouds】
With the development of the project , There are more and more single table data in the database , Related operations are getting slower , At this time, how can we improve our relevant operation efficiency ? Many people have heard of Sub database and sub table , But there is another way of partitioning that may be ignored , When the data volume has not reached the level of tens of millions , We may also be able to use partitioning , Let the data of a table be distributed on different files , Of course, we should be clear that our table data is stored on the disk in the form of files , Partition and sub table mean different things , Partitioning refers to distributing the data of a table to different files according to conditions , Before partitioning, it is stored on a file , But it still points to the same table , Just spread the data to different files , But the sub table spreads the data to different tables , Although the structure is the same , But the name of the table has changed . Partitioning helps us reduce the data per operation , To improve performance .
Encounter the problem of such a large amount of data , We can solve it through the following ideas :
1. shunt ( The principle is : Try to reduce the cardinality of data for each operation ):
1.1. With and without 、 Commonly used and infrequently used are separated .
1.2. Data stored in the database : Partition 、 sub-treasury 、 table .
1.3. Data stored in files : Open the file .
1.4. Consider batching .
2. Cache technology : Read more write less cache .
3. Database optimization : Reasonably design the database structure 、 Build index reasonably 、 Database cluster .
4. Processing optimization : Optimize Sql、 Consider using temporary tables 、 In the middle of table .
5. The rational use of NoSql:Mongodb、Redis、HBase etc. .
6. Distributed big data processing scheme :Hadoop、Spark、Storm etc. .
Here we mainly need to know how to partition the table , What are the advantages and disadvantages of partitioning and what are the precautions for partitioning . Here we are mysql Give examples .
Let's first look at the advantages and disadvantages of partitions :
1. advantage :
• Perform logical data segmentation , Split data can have multiple physical file paths
Next, let's look at the partition method :
1.RANGE Partition : Given the column value of a continuous interval .
Create it as follows :
-
CREATE
TABLE tbl_users1 (
-
uuid
INT
NOT
NULL,
-
name
VARCHAR(
20),
-
registerTime
VARCHAR(
100)
-
)
-
PARTITION
BY
RANGE (uuid) (
-
PARTITION p0
VALUES LESS THAN (
5),
-
PARTITION p1
VALUES LESS THAN (
10),
-
PARTITION p2
VALUES LESS THAN (
15),
-
PARTITION p3
VALUES LESS THAN MAXVALUE
-
);
2.LIST Partition :LIST It is the column value that matches a certain value in a discrete value set to select .
Create it as follows :
-
CREATE
TABLE tbl_users2 (
-
uuid
INT
NOT
NULL,
-
name
VARCHAR(
20),
-
registerTime
VARCHAR(
100)
-
)
-
-
PARTITION
BY List (uuid) (
-
PARTITION p0
VALUES
in (
1,
2,
3,
5),
-
PARTITION p1
VALUES
in (
7,
9,
10),
-
PARTITION p2
VALUES
in (
11,
15)
-
);
3.HASH Partition : The return value of user-defined expression hash The partition selected after calculation , The expression evaluates with the column values of the rows to be inserted into the table , This function must produce non negative integer values .
Create it as follows :
-
CREATE
TABLE tbl_users4 (
-
uuid
INT
NOT
NULL,
-
name
VARCHAR(
20),
-
registerTime
VARCHAR(
100)
-
)
-
PARTITION
BY HASH (uuid)
/
/uuid You can add expressions , such as
/
2, perhaps
mod(uuid,
2), Low performance , Each data should be calculated before hash Then insert
-
PARTITIONS
3;
4.KEY Partition : It's like pressing HASH Partition , from MySQL The server provides its own hash function .
Create it as follows :
-
CREATE
TABLE tbl_users5 (
-
uuid
INT
NOT
NULL,
-
name
VARCHAR(
20),
-
registerTime
VARCHAR(
100)
-
)
-
PARTITION
BY LINEAR Key (uuid)
-
PARTITIONS
3;
In a later article, we will specifically introduce partition operations , No more details here . When partitioning, we need to pay attention to the following situations :
1. If... Exists in the table primary key perhaps unique key when , Partitioned columns are part of one of two
边栏推荐
- 打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
- GFS distributed file system
- IP地址的类别
- 数据分片介绍
- Compilation and linking of programs
- Download and install orcale database11.2.0.4
- Thirteen forms of lambda in kotlin
- National standard gb28181 protocol video platform easygbs adds streaming timeout configuration
- [Yugong series] February 2022 U3D full stack class 005 unity engine view
- 使用AGC重签名服务前后渠道号信息异常分析
猜你喜欢
Obsidan之数学公式的输入
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
Exercise arrangement 2.10, 11
Installation and configuration of PLSQL
A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)
Opencv learning notes 1 -- several methods of reading images
路由信息协议——RIP
Golang compilation constraint / conditional compilation (/ / +build < tags>)
Download and install orcale database11.2.0.4
随机推荐
数据分析方法论与前人经验总结2【笔记干货】
A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)
Installation and configuration of PLSQL
对API接口或H5接口做签名认证
PLSQL的安装和配置
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
Greenplum6.x重新初始化
POJ - 3784 Running Median(对顶堆)
Gson converts the entity class to JSON times declare multiple JSON fields named
Shell script for changing the current folder and the file date under the folder
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
idea里使用module项目的一个bug
Xcit learning notes
GFS distributed file system
ES6_ Arrow function
Quick sorting (detailed illustration of single way, double way, three way)
All about PDF crack, a complete solution to meet all your PDF needs
联想混合云Lenovo xCloud:4大产品线+IT服务门户
About using CDN based on Kangle and EP panel
如何理解分布式架构和微服务架构呢