ITPub博客

首页 > 数据库 > Oracle > MySQL分区之分区概述

MySQL分区之分区概述

原创 Oracle 作者:幕南风 时间:2014-07-03 13:37:08 0 删除 编辑

环境:

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)


 

<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26515977/viewspace-1207892/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 微信O2O细节:《21世纪》与腾讯生活电商部总经理张颖的对话
下一篇: MySQL分区之RANGE分区
请登录后发表评论 登录
全部评论
腾讯数据库工程师

注册时间:2012-05-10

最新文章