Mysql分区表对主键约束等都有一定的限制,下面就对Mysql5.1中Mysql分区表对于主键约束的限制举例进行说明,供您参考学习。
关于Partitioning Keys, Primary Keys, and Unique Keys的限制:
在5.1中Mysql分区表对***约束有明确的规定,每一个***约束必须包含在Mysql分区表的分区键(也包括主键约束)。
这句话也许不好理解,我们做几个实验:
- CREATE TABLE t1
- ( id INT NOT NULL,
- uid INT NOT NULL,
- PRIMARY KEY (id)
- )
- PARTITION BY RANGE (id)
- (PARTITION p0 VALUES LESS THAN(5) ENGINE = INNODB,
- PARTITION p1 VALUES LESS THAN(10) ENGINE = INNODB
- );
- CREATE TABLE t1
- ( id INT NOT NULL,
- uid INT NOT NULL,
- PRIMARY KEY (id)
- )
- PARTITION BY RANGE (id)
- (PARTITION p0 VALUES LESS THAN(5) ENGINE = MyISAM DATA DIRECTORY='/tmp'INDEX DIRECTORY='/tmp',
- PARTITION p1 VALUES LESS THAN(10) ENGINE = MyISAM DATA DIRECTORY='/tmp' INDEX DIRECTORY='/tmp'
- );
- mysql> CREATE TABLE t1
- -> ( id INT NOT NULL,
- -> uid INT NOT NULL,
- -> PRIMARY KEY (id),
- -> UNIQUE KEY (uid)
- -> )
- -> PARTITION BY RANGE (id)
- -> (PARTITION p0 VALUES LESS THAN(5),
- -> PARTITION p1 VALUES LESS THAN(10)
- -> );
- ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function
【编辑推荐】