Partition
MySQL Function: Partition
建立 Partition
CREATE TABLE member (
id INT NOT NULL AUTO_INCREMENT,
age INT NOT NULL,
cont VARCHAR(255) NOT NULL,
PRIMARY KEY(id, age)
)
PARTITION BY range(age) (
PARTITION p0 VALUES LESS THAN (10), -- 0~9
PARTITION p1 VALUES LESS THAN (20), -- 10~19
PARTITION p2 VALUES LESS THAN (30), -- 20~29
PARTITION p3 VALUES LESS THAN (40), -- 30~39
PARTITION p4 VALUES LESS THAN (MAXVALUE) -- over 40
);
异动 Partition
ALTER table member
PARTITION BY RANGE(age) -- partition key must be primary key
PARTITION p0 VALUES LESS THAN (10), -- 0~9
PARTITION p1 VALUES LESS THAN (20), -- 10~19
PARTITION p2 VALUES LESS THAN (30), -- 20~29
PARTITION p3 VALUES LESS THAN (40), -- 30~39
PARTITION p4 VALUES LESS THAN (MAXVALUE) -- over 40
);
Reference
- MySQL :: MySQL 8.0 Reference Manual :: 12.21.2 Window Function Concepts and Syntax
- 简单使用 Mysql Partition 优化查询 - 工作玩乐实验室
- SQL Tips: Select Latest Record for Each Group - Big Box Code