bigint的mysql分区和主键(id)

时间:2014-03-20 12:51:25

标签: mysql bigint partition

我正在测试+ 10小时以获得具有主键(id)的数据库结构 和bigint分区。什么都行不通:/ / 那可能吗? 也许任何人都可以给我一个很好的暗示;)

CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uniqueID` bigint(20) DEFAULT NULL,
  `value` int(11) DEFAULT NULL,
  `m1` text CHARACTER SET utf8,
  `m2` text CHARACTER SET utf8,
  `m3` text CHARACTER SET utf8,
  `m4` text CHARACTER SET utf8,
  `m5` text CHARACTER SET utf8,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniqueID` (`uniqueID`),
  KEY `value` (`value`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci PACK_KEYS=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC
/*!50500 PARTITION BY RANGE  COLUMNS(uniqueID)
(PARTITION p1 VALUES LESS THAN ('0') ENGINE = MyISAM,
 PARTITION p2 VALUES LESS THAN ('1') ENGINE = MyISAM,
 PARTITION p3 VALUES LESS THAN ('2') ENGINE = MyISAM,
 PARTITION p4 VALUES LESS THAN ('3') ENGINE = MyISAM,
 PARTITION p5 VALUES LESS THAN ('4') ENGINE = MyISAM,
 PARTITION p6 VALUES LESS THAN ('5') ENGINE = MyISAM,
 PARTITION p7 VALUES LESS THAN ('6') ENGINE = MyISAM,
 PARTITION p8 VALUES LESS THAN ('9') ENGINE = MyISAM,
 PARTITION p9 VALUES LESS THAN (MAXVALUE) ENGINE = MyISAM) */;

使用这个分区,我会将bigint值除以第一个数字 - 例如:

16275214652090176103将成为分区p2的一部分

此数据库将采用100M记录:/

感谢提前

1 个答案:

答案 0 :(得分:0)

您要分区的列必须是表的主键的一部分,我相信它必须是主键中的最后一列。因此,如果您要将主键定义为PRIMARY KEY(iduniqueID),则应该能够对uniqueID进行分区。

话虽如此,鉴于您的uniqueID字段是bigint并且您尝试基于bigint小于字符串进行分区,我不确定您要执行的操作将按预期工作。也许使用散列分区而不是范围分区会对你有用吗?有关详细信息,请参阅https://dev.mysql.com/doc/refman/5.1/en/partitioning-hash.html