mysql分区表的维护

范围,list分区表维护
删除分区
ALTER TABLE tr DROP PARTITION p2;
添加分区
ALTER TABLE members ADD PARTITION (PARTITION p3 VALUES LESS THAN (2000));
如果添加的分区比第一个分区小,就需要重新组织分区
ALTER TABLE members
REORGANIZE PARTITION p0 INTO (
PARTITION n0 VALUES LESS THAN (1960),
PARTITION n1 VALUES LESS THAN (1970)
);
ALTER TABLE tt ADD PARTITION (PARTITION p2 VALUES IN (7, 14, 21));
合并分区
ALTER TABLE members REORGANIZE PARTITION s0,s1 INTO (
PARTITION p0 VALUES LESS THAN (1970)
);
hash和key分区不能直接删除分区,要想合并分区,使用
ALTER TABLE clients COALESCE PARTITION 4;合并4个分区
ALTER TABLE clients ADD PARTITION PARTITIONS 6;增加6个分区
和表交换分区或子分区
ALTER TABLE pt EXCHANGE PARTITION p WITH TABLE nt
nt不能是临时表,nt的数据范围不能超过p
ALTER TABLE e2 REMOVE PARTITIONING;–使用create table like的方式创建表,是跟原表一样的,要变成普通的表可以使用这个语句。
查看分区的信息
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = ‘e’;
要想查看select使用了哪些分区,使用下面的语句来查看
EXPLAIN PARTITIONS SELECT * FROM trb1 WHERE id < 5\G
分区裁剪是自动做的,选择分区可以明确的指定要操作哪些分区
SELECT * FROM employees PARTITION (p1);
SELECT store_id, COUNT(department_id) AS c FROM employees PARTITION (p1,p2,p3) GROUP BY store_id HAVING c > 4;–这些操作都是可以的
DELETE FROM employees PARTITION (p0, p1) WHERE fname LIKE ‘j%’;
UPDATE employees PARTITION (p0) SET store_id = 2 WHERE fname = ‘Jill’;

你可能感兴趣的:(mysql分区表的维护)