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
MySQL環境變量配置說明
定義MySQL事務的例子
mysql存儲過程問題解答
創建MySQL存儲過程示例
MYSQL IFNULL函數的使用