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

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

猜你喜欢

转载自blog.csdn.net/huryer/article/details/103798688