1.Range(范围)
按照某个字段的范围进行分区。这种常用在时间字段上。
CREATE TABLE article ( article_id int NOT NULL AUTO_INCREMENT, article_content varchar(1000), article_time DATE NOT NULL DEFAULT '1970-01-01', key(article_id) ) ENGINE=INNODB PARTITION BY RANGE (YEAR(article_time)) ( PARTITION p0 VALUES LESS THAN (1991), PARTITION p1 VALUES LESS THAN (1996), PARTITION p2 VALUES LESS THAN (2001), PARTITION p3 VALUES LESS THAN MAXVALUE ) ;
2.Hash(哈希)
按照表中任意个int类型的字段进行分割
CREATE TABLE part_table ( id int NOT NULL AUTO_INCREMENT, name varchar(30), store_id int, key(id) ) ENGINE=INNODB PARTITION BY HASH(store_id) PARTITIONS 4;
3.Key(键值)
Hash partition的进阶版,将主键作为分割的标准
CREATE TABLE part_table2 ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(30), store_id int ) ENGINE=INNODB PARTITION BY KEY() PARTITIONS 4;
4.List(预定义列表)
按照某个字段有哪些值分在一个分区内
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT, store_id INT ) PARTITION BY LIST(store_id) ( PARTITION pNorth VALUES IN (3,5,6,9,17), PARTITION pEast VALUES IN (1,2,10,11,19,20), PARTITION pWest VALUES IN (4,12,13,14,18), PARTITION pCentral VALUES IN (7,8,15,16) );
5.Composite(复合模式)