Mysql分区

来源:互联网 发布:淘宝什么评论有福利 编辑:程序博客网 时间:2024/06/05 07:12
  • 分区概述
    • 分区有利于管理非常大的表,它采用了“分而治之”的逻辑,分区引入了分区键的概念,分区键用于根据某个区间值(或者范围)、特定值列表或者HASH函数执行数据的聚集,让数据根据规则分布在不同的分区中,让一个大对象变成一些小对象。
  • 分区类型
    • RANGE分区:基于一个给定连续区间范围,把数据分配到不同的分区。
    • LIST分区:类似RANGE分区,区别在LIST分区是基于枚举出的值列表分区,RANGE是基于给定的连续区间范围分区
    • HASH分区:基于给定的分区个数,把数据分配到不同的分区
    • KEY分区:类似HASH分区
  • Range分区
create table emp(
id int not null,
ename varchar(30),
hired date not null default '1970-01-01',
separeted date not null default '9999-12-31',
job varchar(30) not null,
store_id int not null)
partition by range(store_id))(
partition p0 values less than(10),
partition p1 values less than(20),
partition p2 values less than(30));
  • List分区
create table expenses(
expense_date date not null,
category int,
amount decimal (10,3)
)partition by list(category)(
partition p0 values in (3,5),
partition p1 values in (1,10),
partition p2 values in (4,9),
partition p3 values in (2),
partition p4 values in (6));
  • Hash分区
create table emp(
id int not null,
ename varchar(30),
hired date not null default '1970-01-01',
separated date not null default '9999-12-31',
job varchar(30) not null,
store_id int not null)
partition by hash(store_id) partition 4;
  • Key分区
create table emp(
id int not null,
ename varchar(30),
hired date not null default '1970-01-01',
separated date not null default '9999-12-31',
job varchar(30) not null,
store_id int not null)
partition by key(job) partitions 4;


原创粉丝点击