mysql8-表分区-hash分区
mysql8-表分区-hash分区mysql版本show variables like '%version%';| version| 8.0.16|| version_comment| MySQL Community Server - GPL |hash分区-- 创建hash分区表...
·
mysql8-表分区-hash分区
mysql版本
show variables like '%version%';
| version | 8.0.16 |
| version_comment | MySQL Community Server - GPL |
创建hash分区表
CREATE TABLE t1 (c1 INT, c2 CHAR(5), c3 DATE)
PARTITION BY HASH( YEAR(c3) )
PARTITIONS 4;
查看分区信息
如果指定分区数为4,则分区名称为:p0~p4
select table_schema, table_name, partition_name,partition_method,partition_expression
from information_schema.PARTITIONS
where table_name ='t1';
数据分区号分配策略
N = MOD(expr, num)
N:分区号
expr:hash方式,如基于列或函数
num:分区数量
示例:如果年份为2019年,分区数为4,则分区号=mod(2019,4)=3
写入测试数据
insert into t1 values(1,'a1','2016-01-01');
insert into t1 values(2,'a2','2017-01-01');
insert into t1 values(3,'a3','2018-01-01');
insert into t1 values(4,'a4','2019-01-01');
-- 查询数据
select * from t1;
-- 查看分区数据
select * from t1 partition(p0);
select * from t1 partition(p1);
select * from t1 partition(p2);
select * from t1 partition(p3);
参考:
https://dev.mysql.com/doc/refman/8.0/en/partitioning-hash.html
更多推荐
已为社区贡献3条内容
所有评论(0)