mysql8-表分区-List分区

创建基于列表的分区表

-- 删除已有表
drop TABLE employees ;

-- 创建列表分区表
CREATE TABLE employees (
    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,
    store_id INT
)
PARTITION BY LIST(store_id) (
    PARTITION pNorth VALUES IN (3,5,6,9,17),
    PARTITION pEast VALUES IN (1,2,10,11,19,20),
    PARTITION pWest VALUES IN (4,12,13,14,18),
    PARTITION pCentral VALUES IN (7,8,15,16)
);

-- 查看分区信息
select * from information_schema.PARTITIONS
where table_name ='employees';

-- 写入测试数据
insert into employees(id,fname,lname,hired,separated,job_code,store_id) values(1,'f1','l1','2019-12-01','2020-01-01',1,1);
insert into employees(id,fname,lname,hired,separated,job_code,store_id) values(2,'f2','l2','2019-12-02','2020-01-01',1,6);
insert into employees(id,fname,lname,hired,separated,job_code,store_id) values(3,'f3','l3','2019-12-03','2020-01-01',1,12);
insert into employees(id,fname,lname,hired,separated,job_code,store_id) values(4,'f4','l4','2019-12-04','2020-01-01',1,16);

-- 查询
select * from employees;

-- 按分区查询
select * from employees partition(pnorth);
select * from employees partition(pEast);
select * from employees partition(pWest);
select * from employees partition(pCentral);

-- 清除数据
delete from employees;

参考

https://dev.mysql.com/doc/refman/8.0/en/partitioning-list.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值