mysql--hash--key分区

hash分区
Hash分区主要用来确保数据在预先确定数目的分区中平均分布,Hash括号内只能是整数列或返回确定整数的函数,实际上就是使用返回的整数对分区数取模。

要使用HASH分区来分割一个表,要在CREATE TABLE 语句上添加一个“PARTITION BY HASH (expr)”子句,其中“expr”是一个返回一个整数的表达式。它可以仅仅是字段类型为MySQL整型的一列的名字。此外,你很可能需要在后面再添加一个“PARTITIONS num”子句,其中num是一个非负的整数,它表示表将要被分割成分区的数量。

如果没有包括一个PARTITIONS子句,那么分区的数量将默认为1

create table staff_hash(
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 not null default 0,
store_id int not null default 0
)
partition by hash(store_id)
partitions 4;

create table staff_hash1(
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 not null default 0,
store_id int not null default 0
)
partition by hash(store_id);

猜你喜欢

转载自blog.csdn.net/qq_28752033/article/details/83993486