mysql 主键分区

mysql 主键分区

通常对于数据比较多的表,可以采用字段分区,一般是id,首先需要把id指定为bigint(20)类型,然后进行id分区

ALTER TABLE `sh_ad_hit` PARTITION BY RANGE (id)
PARTITIONS 21
(PARTITION `p0` VALUES LESS THAN (10000000),
PARTITION `p1` VALUES LESS THAN (20000000),
PARTITION `p2` VALUES LESS THAN (30000000),
PARTITION `p3` VALUES LESS THAN (40000000),
PARTITION `p4` VALUES LESS THAN (50000000),
PARTITION `p5` VALUES LESS THAN (60000000),
PARTITION `p6` VALUES LESS THAN (70000000),
PARTITION `p7` VALUES LESS THAN (80000000),
PARTITION `p8` VALUES LESS THAN (90000000),
PARTITION `p9` VALUES LESS THAN (100000000),
PARTITION `p10` VALUES LESS THAN (110000000),
PARTITION `p11` VALUES LESS THAN (120000000),
PARTITION `p12` VALUES LESS THAN (130000000),
PARTITION `p13` VALUES LESS THAN (140000000),
PARTITION `p14` VALUES LESS THAN (150000000),
PARTITION `p15` VALUES LESS THAN (160000000),
PARTITION `p16` VALUES LESS THAN (170000000),
PARTITION `p17` VALUES LESS THAN (180000000),
PARTITION `p18` VALUES LESS THAN (190000000),
PARTITION `p19` VALUES LESS THAN (200000000),
PARTITION `p20` VALUES LESS THAN (MAXVALUE) 
);

这里是做了20个分区,注意最后一个分区是为了防止数据填满了p19从而无法继续插入数据而做的分区,指定了MAXVALUE就不会受p19限制,而会限制在该字段能承受的最大值。

你可能感兴趣的:(mysql分区)