环境:
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.5.28 |
+-----------+
1 row in set (0.00 sec)
分区是一种表的设计模式
分区,分而治之,其重点在于高可用(管理),而附属价值才是性能的提高
而且:
对存储引擎层透明
对应用程序层透明
支持的分区类型:
对于表:
▼ 水平分区 → 同一表中不同行的记录分配到不同的物理文件
对于索引:
▼ 局部分区索引 → 一个分区既存放数据又存放索引
可以用下列命令查询当前数据库是否启用了分区功能:
mysql> show variables like '%partition%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| have_partitioning | YES |
+-------------------+-------+
1 row in set (0.00 sec)
MySQL分区类型:
● RANGE 分区
● LIST 分区
● HASH 分区
● KEY 分区
不论创建何种类型的分区,如果表存在主键或者唯一性索引时,分区列必须是唯一性索引的一个组成部分。
mysql> create table t( col1 int not null,
-> col2 int not null,
-> col3 int not null,
-> col4 int not null,
-> unique key (col1,col2)
-> )
-> partition by hash(col3)
-> partitions 4;
ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
mysql> create table t( col1 int not null,
-> col2 int not null,
-> col3 int not null,
-> col4 int not null,
-> unique key (col1,col2)
-> )
-> partition by hash(col2)
-> partitions 4;
Query OK, 0 rows affected (0.08 sec)