我的表格如下:
CREATE TABLE TEST_P (
ID VARCHAR(64),
F_NAME int NOT NULL,
L_NAME VARCHAR(64),
CREATETS DATETIME NOT NULL,
PRIMARY KEY(DATA_TRACE_ID,CREATETS)
)
PARTITION BY RANGE(DAY(CREATETS))(
PARTITION day1 VALUES LESS THAN (2),
PARTITION day2 VALUES LESS THAN (3),
PARTITION day3 VALUES LESS THAN (4),
PARTITION day4 VALUES LESS THAN (5),
PARTITION day5 VALUES LESS THAN (6),
PARTITION day6 VALUES LESS THAN (7),
PARTITION day7 VALUES LESS THAN (8),
PARTITION day8 VALUES LESS THAN (9),
PARTITION day9 VALUES LESS THAN (10),
PARTITION day10 VALUES LESS THAN (11),
PARTITION day11 VALUES LESS THAN (12),
PARTITION day12 VALUES LESS THAN (13),
PARTITION day13 VALUES LESS THAN (14),
PARTITION day14 VALUES LESS THAN (15),
PARTITION day15 VALUES LESS THAN (16),
PARTITION day16 VALUES LESS THAN (17),
PARTITION day17 VALUES LESS THAN (18),
PARTITION day18 VALUES LESS THAN (19),
PARTITION day19 VALUES LESS THAN (20),
PARTITION day20 VALUES LESS THAN (21),
PARTITION day21 VALUES LESS THAN (22),
PARTITION day22 VALUES LESS THAN (23),
PARTITION day23 VALUES LESS THAN (24),
PARTITION day24 VALUES LESS THAN (25),
PARTITION day25 VALUES LESS THAN (26),
PARTITION day26 VALUES LESS THAN (27),
PARTITION day27 VALUES LESS THAN (28),
PARTITION day28 VALUES LESS THAN (29),
PARTITION day29 VALUES LESS THAN (30),
PARTITION day30 VALUES LESS THAN (31),
PARTITION day31 VALUES LESS THAN MAXVALUE
);
我想编写一个脚本,删除今天+1天的分区,并为该分区创建一个具有相同分区条件的新分区。 例如:
我想删除第5天分区,因为我想删除此表中的数据。
我正在这样做:
ALTER TABLE TEST_P REORGANIZE PARTITION day5 into
(PARTITION day5 VALUES LESS THAN (5),
PARTITION day6 VALUES LESS THAN (6),
PARTITION day7 VALUES LESS THAN (7),
PARTITION day8 VALUES LESS THAN (8),
PARTITION day9 VALUES LESS THAN (9),
PARTITION day10 VALUES LESS THAN (10),
PARTITION day11 VALUES LESS THAN (11),
PARTITION day12 VALUES LESS THAN (12),
PARTITION day13 VALUES LESS THAN (13),
PARTITION day14 VALUES LESS THAN (14),
PARTITION day15 VALUES LESS THAN (15),
PARTITION day16 VALUES LESS THAN (16),
PARTITION day17 VALUES LESS THAN (17),
PARTITION day18 VALUES LESS THAN (18),
PARTITION day19 VALUES LESS THAN (19),
PARTITION day20 VALUES LESS THAN (20),
PARTITION day21 VALUES LESS THAN (21),
PARTITION day22 VALUES LESS THAN (22),
PARTITION day23 VALUES LESS THAN (23),
PARTITION day24 VALUES LESS THAN (24),
PARTITION day25 VALUES LESS THAN (25),
PARTITION day26 VALUES LESS THAN (26),
PARTITION day27 VALUES LESS THAN (27),
PARTITION day28 VALUES LESS THAN (28),
PARTITION day29 VALUES LESS THAN (29),
PARTITION day30 VALUES LESS THAN (30),
PARTITION day31 VALUES LESS THAN (31),
PARTITION p_default VALUES LESS THAN MAXVALUE)
但我知道
要重组的分区列表中的错误
此表的增长非常快,因此我想删除一个月的数据,而又不影响表的性能。
答案 0 :(得分:0)
滑动时间序列是PARTITIONing
的少数几个用例之一。不幸的是,您的方法效率低下(如果可以解决的话)。
取而代之的是,有实际的天数(而不是每月的某天),并每晚增加一个新分区-通过REORGANIZEing
将“ future”分区划分为明天的日期和一个新的“ future”。另外,DROP PARTITION
折腾最旧的。详细信息here。