2

我有一个名为 tbl_rtdata 的表。我删除了该表中的所有分区并以以下方式创建新分区。

ALTER TABLE tbl_rtdata  PARTITION BY RANGE (Month(fld_date))

SUBPARTITION BY HASH (Day(fld_date)) SUBPARTITIONS 12(   
PARTITION Apr_0 VALUES LESS THAN (2012-05-01),
PARTITION May_1 VALUES LESS THAN (2012-06-01),    
PARTITION Jun_2 VALUES LESS THAN (2012-07-01),  
PARTITION Jul_3 VALUES LESS THAN (2012-08-01),
PARTITION Aug_4 VALUES LESS THAN (2012-09-01),
PARTITION Sep_5 VALUES LESS THAN (2012-10-01),
PARTITION Oct_6 VALUES LESS THAN (2012-11-01),  
PARTITION Nov_7 VALUES LESS THAN (2012-12-01),
PARTITION Dec_8 VALUES LESS THAN MAXVALUE );

但我得到一个错误: VALUES LESS THAN value must be strictly increasing for each partition.

如果我在查询中删除子分区,则会显示分区“Apr_0”的错误 VALUES 值必须具有 INT 类型

我应该怎么做才能从中恢复?

4

2 回答 2

2

我找到了非常简单的答案,使用 to_days 函数

ALTER TABLE tbl_rtdata  PARTITION BY RANGE (Month(fld_date))
(   
PARTITION p_Apr VALUES LESS THAN (TO_DAYS('2012-05-01')),
PARTITION p_May VALUES LESS THAN (TO_DAYS('2012-06-01')), 
PARTITION p_Jun VALUES LESS THAN (TO_DAYS('2012-07-01')),  
PARTITION p_Jul VALUES LESS THAN (TO_DAYS('2012-08-01')),
PARTITION p_Aug VALUES LESS THAN (TO_DAYS('2012-09-01')),
PARTITION p_Sep VALUES LESS THAN (TO_DAYS('2012-10-01')),
PARTITION p_Oct VALUES LESS THAN (TO_DAYS('2012-11-01')),  
PARTITION p_Nov VALUES LESS THAN (TO_DAYS('2012-12-01')),
PARTITION p_Dec VALUES LESS THAN MAXVALUE );
于 2012-08-10T11:48:26.143 回答
2

我认为MySQL < 5.5 尝试这个不支持:Manual here

ALTER TABLE tbl_rtdata PARTITION BY RANGE COLUMNS (fld_date) (
  PARTITION Apr_0 VALUES LESS THAN ('2012-05-01'),
  PARTITION May_1 VALUES LESS THAN ('2012-06-01'),
  PARTITION Dec_8 VALUES LESS THAN (MAXVALUE)
  );
于 2012-08-08T07:18:46.830 回答