我正在尝试根据年份范围对表进行分区。
但我收到以下错误“#1503 - 主键必须包含表分区函数中的所有列”。
以下是我的查询
CREATE TABLE IF NOT EXISTS `t2123` (
`j_id` int(11) NOT NULL AUTO_INCREMENT,
`u_id` int(11) NOT NULL,
`w_id` int(5) NOT NULL,
`p_id` int(5) NOT NULL,
`s_p_id` int(5) NOT NULL,
`p_t` tinyint(3) unsigned NOT NULL,
`a_n` int(5) NOT NULL,
`type` enum('GP','NGP','PGP','PAGP') NOT NULL,
`p_p` int(11) NOT NULL,
`s_p` int(11) NOT NULL,
`p_c` float NOT NULL,
`s_c` float NOT NULL,
`s_p_p_c` float NOT NULL DEFAULT '0',
`g_d` date NOT NULL,
`datetimes` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`c_c` double DEFAULT '0',
`c_m` double DEFAULT '0',
`c_y` double DEFAULT '0',
`c_k` double DEFAULT '0' ,
`c_total` double DEFAULT '0' ,
`p_a` float DEFAULT '0',
PRIMARY KEY (`j_id`),
UNIQUE KEY(j_id, g_d),
KEY `u_id` (`u_id`),
KEY `w_id` (`w_id`),
KEY `p_id` (`p_id`),
KEY `s_p_id` (`s_p_id`),
KEY `a_n` (`a_n`),
KEY `g_d` (`g_d`)
) engine=myisam PARTITION BY RANGE (j_id + year(g_d)) (
PARTITION t2_2012 VALUES LESS THAN (2012),
PARTITION t2_2013 VALUES LESS THAN (2013)
);
请建议我如何创建分区?
最佳答案
如错误信息所示:
A PRIMARY KEY must include all columns in the table's partitioning function
您的分区函数指的是 j_id
和 g_d
而您的主键仅涵盖 j_id
。
顺便说一句,您的UNIQUE
约束是无用的(UNIQUE KEY(j_id, g_d)
)因为j_id
根据定义已经是唯一的(它是主键)。
事实上你可能想要你的主键在 (j_id, g_d)
关于php - 基于年份的MYISAM引擎在mysql中的表分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17967004/