Is Partition BY RANGE can’t be applied for the table which has auto incremented primary keys?
I’m asking it because saw some (1,2) examples of create table statement which doesn’t have primary key definition. And also my create table statement gives me error:
A PRIMARY KEY must include all columns in the table’s partitioning function
Here is my statement
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)
)
And one more question: could angle column be of double type? Because I’ve got this error when I set it as double:
The PARTITION function returns the wrong type
Thanks.
The first error message is fairly explicit :
You must either partition by your primary key, or include
anglein your primary keyI suppose you do not want the latter, so the former is the solution.
As for the second error:
Indeed, the partition function (here, “
angle” is the so-called “function”, think of it as the identity function) must return an integer, as stated in the manual: