mysql - 错误 "A PRIMARY KEY must include all columns in the table' s 分区函数”

标签 mysql indexing partitioning

将列 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/

相关文章:

mysql - 使用 WHERE 子句的选择结果

php - SQL 插入忽略不起作用

php - 关于如何在 Laravel 5.5 中从 3 个不同的 SQL 表填充 View 中的 HTML 表的建议?

python - Numpy:如何添加/加入切片对象?

Cassandra 主键选择以限制分区增长

MySQL/Apache 冗余服务器设置

mysql - 了解 mysql 元组搜索的性能影响

postgresql - LIMIT 与 ORDER BY 使查询变慢

mysql - 在 MySQL 对表进行分区时,这里如何使用 DIV 作为 HASH 分区定义的一部分?

mysql - 包含 8000 万条记录并添加索引的表需要超过 18 小时(或永远)!怎么办?