Partition table management database up to the dream

Partition table management database up to the dream

Partition table is a data table is divided into a large number of small subset is called the partition, the partition table of a database with a dream range partitioning, hash partitioning, list partitioning, partition gap, and so a variety of combinations of the partition.
Range partitioning: range partitioning is a value range of the data table partition, for example, can be partitioned according to business records of the creation date, decide on which partition the data is stored in.
Partition Hash: Hash partition is uniformly distributed in accordance with the hash value field, the implementation of each possible partition of the hash data are equal.
List Partitioning: list partitioning to explicitly specify the partition according to a specific value for a field, rather than as range partitioning based on the value of the range field to the division.
Interval Partitioning: interval is an interval partition as the partition table "starting point" and adds a definition at regular intervals in the future to know how to add database partitions.

1, up to the dream Range partitioning
Range partitioning: range partitioning is a value range of the data table partition, for example, can be partitioned according to business records of the creation date, decide on which partition the data is stored in.
create table tab_part_fw (id int, name varchar (20), c3 date) partition by range (c3) (partition p1 values less than ( '2019-10-1'), partition p2 values less than ( '2019-11-1 '), partition p3 values less than (' 2019-12-1 '), partition p4 values less than (maxvalue));

insert into tab_part_fw values(1, 'a', '2019-10-1');
insert into tab_part_fw values(2, 'b','2019-11-1');
insert into tab_part_fw values(3, 'c','2019-12-1');
Partition table management database up to the dream

2, the dream of hash partitioning
hash partitioning: the hash partition is uniformly distributed in accordance with the hash value field, the implementation of each possible partition of the hash data are equal.
Table tab_part_hx Create (int ID, name VARCHAR (20 is))
Partition by the hash (ID) (Partition P1, P2 Partition, Partition P3);

insert into tab_part_hx values(1, 'a');
insert into tab_part_hx values( 2, 'b');
insert into tab_part_hx values( 3, 'c');

select * from tab_part_hx partition (p3);
Partition table management database up to the dream

3, up to the dream list partition
list partition: partition list explicitly specify the partition according to a specific value for a field, rather than as range partitioning based on the value of the range field to the division.
Create Table tab_part_lb (C1 int, C2 char (20 is), C3 VARCHAR, C4 DATE)
Partition by List (C2) (
Partition P11 values ( 'AAAA', 'bbbb'),
Partition P12 values ( 'CCCC', 'dddd' ),
Partition P13 values ( 'EEEE', 'FFFF'),
Partition P14 values ( 'GGGG', 'HHHH')
);

insert into tab_part_lb values(1, 'aaaa', 'b', '2019-1-1');
select * from tab_part_lb;
Partition table management database up to the dream

4、达梦间隔分区
间隔分区:间隔分区是以一个区间分区表为"起点",并在定义中增加了一个间隔规则,使数据库知道将来如何增加分区。
create table tab_part_jg (c1 timestamp, c2 varchar(20))
partition by range(c1)
interval(numtoyminterval(1,'month'))
(partition p0 values less than(to_date('2019-01-01','yyyy-mm-dd')));

insert into tab_part_jg values ('2019-07-01','lss');
select * from tab_part_jg;
Partition table management database up to the dream

5、分区维护
对于分区的管理,可以增加分区、可以删除分区、合并分区、拆分分区、交换分区、截断分区、重命名分区、分区表迁移等等。。
比如删除分区,删除刚创建的tab_part_fw表的p4分区
alter table tab_part_fw drop partition p4;
Partition table management database up to the dream

比如合并分区
alter table tab_part_fw merge partitions p1,p2 into partition p1_2;
Partition table management database up to the dream

For example Split Partition
alter table tab_part_fw split partition p1_2 at ( '2019-10-1') into (partition p1, partition p2);
Partition table management database up to the dream

Guess you like

Origin blog.51cto.com/14615334/2463428