Mysql分區表相信大家都有一些了解,下面就為您介紹Mysql分區表對於唯一約束的局限性,如果您對此方面感興趣的話,不妨一看。
Mysql分區表關於Partitioning Keys, Primary Keys, and Unique Keys的限制
在5.1中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
深入探討MySQL鎖機制
詳解MySQL數據表類型
MySQL字段中的枚舉
MySQL添加字段和刪除字段
MySQL字段類型簡介