将列 country_id 上的分区索引添加到下表时,出现错误:
A PRIMARY KEY must include all columns in the table's partitioning function
我尝试将列 country_id 添加到包含 id 和 country_id 的 PK。但是随后出现类似的错误信息:
A UNIQUE KEY must include all columns in the table's partitioning function
CREATE TABLE `geo_city` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`country_id` smallint(5) unsigned NOT NULL,
`admin_zone_id` bigint(20) unsigned DEFAULT NULL,
`name` varchar(128) NOT NULL,
`lat` double NOT NULL,
`lng` double NOT NULL,
`population` int(10) unsigned DEFAULT NULL,
`timezone_id` smallint(5) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_city_id_per_country` (`id`,`country_id`),
UNIQUE KEY `idx_unique_city_per_adminzone` (`admin_zone_id`,`name`),
KEY `country_id` (`country_id`),
KEY `name` (`name`),
KEY `idx_lat_lng` (`lat`,`lng`),
KEY `admin_zone_id` (`admin_zone_id`),
KEY `population` (`population`),
KEY `timezone_id` (`timezone_id`)
) ENGINE=InnoDB AUTO_INCREMENT=496831 DEFAULT CHARSET=utf8;
然后:
ALTER TABLE geo.geo_city PARTITION BY RANGE (country_id) (
PARTITION p0 VALUES LESS THAN (2),
PARTITION p1 VALUES LESS THAN (10),
PARTITION p2 VALUES LESS THAN (20),
PARTITION p3 VALUES LESS THAN (30),
PARTITION pRemain VALUES LESS THAN MAXVALUE
)
现在怎么办?
最佳答案
您需要将所有分区键添加到所有主键和唯一键中。
关于mysql - 错误 "A PRIMARY KEY must include all columns in the table' s 分区函数”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35525323/