MySQL分区之分区概述

环境:

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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值