我尝试对 table 进行分区时出错

Error while I'm trying to partitioning a table

这是我的poststable:

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  

有什么帮助吗?

您要加快哪些查询的速度?由于您当前拥有的唯一索引,因此 WHERE id=...WHERE id BETWEEN ... AND ... 是唯一快速的查询。 并且您建议的分区对其他查询没有多大帮助

你好像只有几十行;不要考虑分区,除非您期望至少有一百万行。

status 只有 5 个值?然后制作ENUM('archive', 'admin', 'moder', 'public', 'rec') NOT NULL。这将占用 1 个字节而不是很多字节。

如果你要查询 date and/or status and/or auth,那么我们来谈谈索引,尤其是 'composite' 索引在这样的。而且,要实现您设想的 "archive" 拆分,请将 status 作为索引中的第一列。