列表分区
列表分区和范围分区类似,主要区别是list partition的分区范围是预先定义好的一系列值,而不是连续的范围。列表分区采用partition by list和values in子句定义。
示例,创建一张员工表按照employee_id进行列表分区:
CREATE TABLE employees (
employee_id int(6) primary key,
first_name varchar(20),
last_name varchar(25),
email varchar(25),
phone_number varchar(20),
hire_date datetime,
job_id varchar(10),
salary int(8),
commission_pct decimal(2,2),
manager_id decimal(6,0),
department_id int(4)
)
PARTITION BY LIST(employee_id) (
PARTITION p0 VALUES IN (101,103,105,107,109),
PARTITION p1 VALUES IN (102,104,106,108,110)
);
INSERT INTO employees VALUES ('100', 'Steven', 'King', 'SKING', '515.123.4567', '1987-06-17 00:00:00', 'AD_PRES', '24000.00', null, null, '90');
INSERT INTO employees VALUES ('101', 'Neena', 'Kochhar', 'NKOCHHAR', '515.123.4568', '1989-09-21 00:00:00', 'AD_VP', '17000.00', null, '100', '90');
INSERT INTO employees VALUES ('102', 'Lex', 'De Haan', 'LDEHAAN', '515.123.4569', '1993-01-13 00:00:00', 'AD_VP', '17000.00', null, '100', '90');
INSERT INTO employees VALUES ('103', 'Alexander', 'Hunold', 'AHUNOLD', '590.423.4567', '1990-01-03 00:00:00', 'IT_PROG', '9000.00', null, '102', '60');
INSERT INTO employees VALUES ('104', 'Bruce', 'Ernst', 'BERNST', '590.423.4568', '1991-05-21 00:00:00', 'IT_PROG', '6000.00', null, '103', '60');
INSERT INTO employees VALUES ('105', 'David', 'Austin', 'DAUSTIN', '590.423.4569', '1997-06-25 00:00:00', 'IT_PROG', '4800.00', null, '103', '60');
INSERT INTO employees VALUES ('106', 'Valli', 'Pataballa', 'VPATABAL', '590.423.4560', '1998-02-05 00:00:00', 'IT_PROG', '4800.00', null, '103', '60');
INSERT INTO employees VALUES ('107', 'Diana', 'Lorentz', 'DLORENTZ', '590.423.5567', '1999-02-07 00:00:00', 'IT_PROG', '4200.00', null, '103', '60');
INSERT INTO employees VALUES ('108', 'Nancy', 'Greenberg', 'NGREENBE', '515.124.4569', '1994-08-17 00:00:00', 'FI_MGR', '12000.00', null, '101', '100');
INSERT INTO employees VALUES ('109', 'Daniel', 'Faviet', 'DFAVIET', '515.124.4169', '1994-08-16 00:00:00', 'FI_ACCOUNT', '9000.00', null, '108', '230');
INSERT INTO employees VALUES ('110', 'John', 'Chen', 'JCHEN', '515.124.4 269', '1997-09-28 00:00:00', 'FI_ACCOUNT', '8200.00', null, '108', '100');
查询0号分区:
select * from employees partition(p0);
select * from employees partition(p1);
select * from employees partition(p0,p1);
和range分区一样,可以使用alter table … add/drop partition新增/删除分区:
ALTER TABLE employees ADD PARTITION(PARTITION p2 VALUES IN (111,112,113,114,115));
ALTER TABLE employees DROP PARTITION p2;
LIST COLUMNS分区表,分区字段支持使用CHAR VARCHAR DATE等数据类型。普通的LIST分区表分区字段必须是INT类型。文章来源:https://www.toymoban.com/news/detail-571912.html
CREATE TABLE employees (
employee_id int(6),
first_name varchar(20),
last_name varchar(25),
email varchar(25),
phone_number varchar(20),
hire_date datetime,
job_id varchar(10),
salary int(8),
commission_pct decimal(2,2),
manager_id decimal(6,0),
department_id int(4)
)
PARTITION BY LIST COLUMNS(last_name) (
PARTITION p0 VALUES IN (‘King’,‘Grant’),
PARTITION p1 VALUES IN (‘Scott’,‘Jim’)
);文章来源地址https://www.toymoban.com/news/detail-571912.html
到了这里,关于mysql分区表 -列表分区(list prtition)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!