Partition
MySQL Function: Partition
Categories:
Create 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
);
Alter 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