mysql8-表分区-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

发布了230 篇原创文章 · 获赞 29 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/huryer/article/details/103918576
今日推荐