MySQL用子分区重组分区

时间:2018-07-28 16:53:00

标签: mysql

我有一个按年划分的mysql表,按月划分的子表。 这里是创建语句。

CREATE TABLE `my_table` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `created_at` date NOT NULL,
 `language` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL,
 `title` text COLLATE utf8mb4_unicode_ci,
 PRIMARY KEY (`id`,`created_at`),
 KEY `created_at` (`created_at`),

) ENGINE=InnoDB AUTO_INCREMENT=1724800187 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8
/*!50100 PARTITION BY RANGE (YEAR(created_at))
SUBPARTITION BY HASH ( MONTH(created_at))
SUBPARTITIONS 12
(PARTITION p0 VALUES LESS THAN (2016) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2017) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */

我想重组分区,以便p2仅包含2018年数据,而新分区(p3,p4和p5)将包含未来几年的数据。

在这种情况下,使用以下语句执行“重组分区”是否正确?

ALTER TABLE `my_table` REORGANIZE PARTITION `p2` INTO 
( 
  PARTITION `p2` VALUES LESS THAN (2018) ENGINE = InnoDB, 
  PARTITION `p3` VALUES LESS THAN (2019) ENGINE = InnoDB,
  PARTITION `p4` VALUES LESS THAN (2020) ENGINE = InnoDB,
  PARTITION `p5` VALUES LESS THAN MAXVALUE 
);

谢谢!

0 个答案:

没有答案