gpt4 book ai didi

MySQL Partition BY RANGE 不适用于主键?

转载 作者:行者123 更新时间:2023-11-29 00:38:41 25 4
gpt4 key购买 nike

Partition BY RANGE是否不能应用于主键自增的表?我问它是因为看到一些( 12 )没有主键定义的创建表语句的例子。而且我的创建表语句给我错误:

A PRIMARY KEY must include all columns in the table's partitioning function

这是我的声明

CREATE TABLE `tbl_point` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cord_x` double DEFAULT NULL,
`cord_y` double DEFAULT NULL,
`angle` int DEFAULT NULL,
PRIMARY KEY (`id`)
)
PARTITION BY RANGE (angle) (
PARTITION p0 VALUES LESS THAN (91),
PARTITION p1 VALUES LESS THAN (181),
PARTITION p2 VALUES LESS THAN (271),
PARTITION p3 VALUES LESS THAN (361)
)

还有一个问题:angle 列可以是 double 类型吗?因为当我将它设置为 double 时出现了这个错误:

The PARTITION function returns the wrong type

谢谢。

最佳答案

第一条错误信息相当明确:

A PRIMARY KEY must include all columns in the table's partitioning function

您必须按主键进行分区,或者在主键中包含 angle

我想你不想要后者,所以前者是解决方案。

关于第二个错误:

The PARTITION function returns the wrong type

的确,分区函数(这里的“angle”就是所谓的“函数”,可以把它看成恒等函数)必须返回一个整数,如in the manual所述:

A partitioning key must be either an integer column or an expression that resolves to an integer.

关于MySQL Partition BY RANGE 不适用于主键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13235221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com