这是我的posts
表:
CREATE TABLE `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`img` varchar(255) COLLATE utf8_croatian_ci NOT NULL,
`vid` varchar(255) COLLATE utf8_croatian_ci NOT NULL,
`title` varchar(255) COLLATE utf8_croatian_ci NOT NULL,
`subtitle` varchar(255) COLLATE utf8_croatian_ci NOT NULL,
`auth` varchar(54) COLLATE utf8_croatian_ci NOT NULL,
`story` longtext COLLATE utf8_croatian_ci NOT NULL,
`tags` varchar(255) COLLATE utf8_croatian_ci NOT NULL,
`status` varchar(100) COLLATE utf8_croatian_ci NOT NULL,
`moder` varchar(50) COLLATE utf8_croatian_ci NOT NULL,
`rec` varchar(50) COLLATE utf8_croatian_ci NOT NULL,
`pos` varchar(50) COLLATE utf8_croatian_ci NOT NULL,
`inde` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=117 DEFAULT CHARSET=utf8 COLLATE=utf8_croatian_ci
我想制作两个分区以提高查询性能
第一个分区应包含所有non-archive
行
第二个分区 - 所有archive
行。
ALTER TABLE posts
PARTITION BY LIST COLUMNS (status)
(
PARTITION P1 VALUES IN ('admin', 'moder', 'public', 'rec'),
PARTITION P2 VALUES IN ('archive')
);
phpmyadmin错误:
Static analysis:
1 errors were found during analysis.
Unrecognized alter operation. (near "" at position 0)
MySQL said:
#1503 - A PRIMARY KEY must include all columns in the table's partitioning function
任何帮助?
答案 0 :(得分:1)
您想加快哪些疑问?由于您目前拥有唯一的索引,WHERE id=...
或WHERE id BETWEEN ... AND ...
是唯一快速的查询。 您建议的分区对其他查询无效。
你似乎只有几十行;不要考虑分区,除非你期望至少有一百万行。
status
只有5个值吗?然后将其ENUM('archive', 'admin', 'moder', 'public', 'rec') NOT NULL
。这需要1个字节而不是很多。
如果您要查询date
和/或status
和/或auth
,那么让我们谈谈索引,尤其是“复合”索引。并且,为了实现您想象的“存档”拆分,将status
作为索引中的第一列。