在现有mysql表上创建分区

时间:2015-05-20 12:13:17

标签: mysql sql partitioning sharding

下面是我的表结构,150k记录

CREATE TABLE `employees` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `emailid` varchar(255) DEFAULT NULL,
  `join_date` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`id`,`join_date`)
) ENGINE=InnoDB 

我使用的是mysql版本:5.5.41

数据报告:

+------------+-----------+
| join_date  | count     |
+------------+-----------+
| 2015-05-01 |       100 |
| 2015-05-02 |       100 |
| 2015-05-03 |       100 |
| 2015-05-04 |       100 |
| 2015-05-05 |       100 |
| 2015-05-06 |       100 |
| 2015-05-07 |     67900 |
| 2015-05-08 |     30622 |
| 2015-05-09 |     10455 |
| 2015-05-10 |     40393 |
+------------+-----------+

当我尝试执行以下命令时

Alter Table employees  PARTITION by RANGE (TO_DAYS(join_date)) 
      ( PARTITION p1 values less than (TO_DAYS('2015-05-07'))); 

我收到以下错误:表没有值736090的分区。即使我有600条记录低于值2015-05-07

我做错了什么。

1 个答案:

答案 0 :(得分:3)

不确定,但我认为你应该尝试:

ALTER TABLE employees PARTITION BY RANGE (TO_DAYS(join_date)) (
    PARTITION p1 values LESS THAN(TO_DAYS('2015-05-07')),
    PARTITION p2 VALUES LESS THAN(MAXVALUE)
);