分区表类型
注:分区表的每个唯一键或者主键必须包含分区表达式中的所有列;
有效分区表
mysql> show create table hero5\G
*************************** 1. row ***************************
Table: hero5
Create Table: CREATE TABLE `hero5` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT '',
`status` int(11) NOT NULL DEFAULT '-1',
PRIMARY KEY (`id`,`status`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH( `status` )
PARTITIONS 4
1 row in set (0.00 sec)
无效分区表
mysql> create table hero6(id int not null auto_increment,name varchar(100) default '',status int default -1,primary key(id))partition by HASH(status) partitions 4;
ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function