您的位置:首页 > 数据库

Greenplum6 数据库数据库学习_分区表

2021-04-15 00:14 531 查看

Greenplum 分区原理

分区表意思是将一个大表在物理上分割成几块,GPDB中的分区表和PostgreSQL中实现原理一样,都是用过表继承、约束来实现。但是与PostgreSQL也有所不同,在PostgreSQL中,一个父表,多个子表来实现分区表,需要手动向子表插入数据,如果向父表插入数据,则直接会被插入到父表中,在GPDB中,可以直接想父表插入数据,便可以根据约束直接自动向对应的子表插入数据,当分区子表不存在时,插入失败

语法

[PARTITION BY partition_type (column)
[SUBPARTITION BY partition_type (column)]
[SUBPARTITION TEMPLATE (template_spec)]
[...]
(partition_spec)
|[SUBPARTITION BY partition_type(column)]
[...]
(partition_spec)
[(subpartition_spec
[(...)]
)]
]
and partition_element is:

DEFAULT PARTITION name
| [PARTITION name] VALUES (list_value[,...])
| [PARTITION name]
START ([datatype] 'start_value') [INCLUSIVE|EXCLUSIVE]
[ END ([datatype] 'end_value') [INCLUSIVE|EXCLUSIVE]
[ EVERY ([datatype] [number|INTERVAL] 'interval_value')]
| [PARTITION name]
END ([DATATYPE] 'end_value') [INCLUSIVE|EXCLUSIVE]
[ EVERY ([datatype] [number|INTERVAL] 'interval_value')]
[ with (partition_storage_parameter=value [,...])]
[ TABLESPACE tablespace]

普通分区

range分区

create table public.test_partition_range(
id numeric,
name character varying(32),
dw_end_date date
) distributed by (id)
PARTITION BY range(dw_end_date)
(
PARTITION p20201230 START ('2020-12-30'::date) END ('2020-12-31'::date),
PARTITION p20201231 START ('2020-12-31'::date) END ('2021-01-01'::date),
PARTITION p20210101 START ('2021-01-01'::date) END ('2021-01-02'::date),
PARTITION p20210102 START ('2021-01-02'::date) END ('2021-01-03'::date),
PARTITION p20210103 START ('2021-01-03'::date) END ('2021-01-04'::date),
PARTITION p20210104 START ('2021-01-04'::date) END ('2021-01-05'::date),
PARTITION p20210105 START ('2021-01-05'::date) END ('2021-01-06'::date)
);

create table test_partition_range1
(
id int,
name varchar(64),
fdate varchar(64)
) distributed by (id)
partition by range(fdate)
(
partition p1 start ('2017-01-01') inclusive end ('2017-01-31') exclusive,
partition p2 start ('2017-02-01') inclusive end ('2017-02-29') exclusive,
default partition default_p
);

create table test_partition_range
(
id int,
name varchar(64),
fdate varchar(64)
) distributed by (id)
partition by range(fdate)
(
partition p1 start ('2017-01-01') inclusive end ('2017-01-31') exclusive,
partition p2 start ('2017-02-01') inclusive end ('2017-02-29') exclusive,
default partition default_p
);

inclusive :指定包含,例如上面的 start ('2017-01-01') inclusive 则是包含'2017-01-01'
exclusive : 指定不包含, 例如上面的 end ('2017-01-31') exclusive 则是不包含'2017-01-31'

执行结果显示

testDB=# create table public.test_partition_range(
testDB(#   id numeric,
testDB(#   name character varying(32),
testDB(#   dw_end_date date
testDB(# ) distributed by (id)
testDB-# PARTITION BY range(dw_end_date)
testDB-# (
testDB(#     PARTITION p20201230 START ('2020-12-30'::date) END ('2020-12-31'::date),
testDB(#     PARTITION p20201231 START ('2020-12-31'::date) END ('2021-01-01'::date),
testDB(#     PARTITION p20210101 START ('2021-01-01'::date) END ('2021-01-02'::date),
testDB(#     PARTITION p20210102 START ('2021-01-02'::date) END ('2021-01-03'::date),
testDB(#     PARTITION p20210103 START ('2021-01-03'::date) END ('2021-01-04'::date),
testDB(#     PARTITION p20210104 START ('2021-01-04'::date) END ('2021-01-05'::date),
testDB(#     PARTITION p20210105 START ('2021-01-05'::date) END ('2021-01-06'::date)
testDB(# );
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20201230" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20201231" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20210101" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20210102" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20210103" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20210104" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p20210105" for table "test_partition_range"
CREATE TABLE
testDB=# create table test_partition_range1
testDB-# (
testDB(#     id int,
testDB(#     name varchar(64),
testDB(#     fdate varchar(64)
testDB(#     ) distributed by (id)
testDB-#     partition by range(fdate)
testDB-#     (
testDB(#         partition p1 start ('2017-01-01') inclusive end ('2017-01-31') exclusive,
testDB(#         partition p2 start ('2017-02-01') inclusive end ('2017-02-29') exclusive,
testDB(#         default partition default_p
testDB(#     );
NOTICE:  CREATE TABLE will create partition "test_partition_range1_1_prt_default_p" for table "test_partition_range1"
NOTICE:  CREATE TABLE will create partition "test_partition_range1_1_prt_p1" for table "test_partition_range1"
NOTICE:  CREATE TABLE will create partition "test_partition_range1_1_prt_p2" for table "test_partition_range1"
CREATE TABLE

every range分区(快速分区(every))

create table public.test_partition_every(
id numeric,
name character varying(32),
dw_end_date date
) distributed by(id)
partition by range(dw_end_Date)
(
partition p202012 start('2020-12-1'::date) end ('2021-12-31'::date)
every ('1 days'::interval)
);

eg:根据选定的范围,跨越基数,快速分区每一个子表
create table test_partition_every_1
(
id int,
name varchar(64),
fdate date
)
distributed by (id)
partition by range (fdate)
(
partition pn_ start ('2017-01-01'::date) end ('2017-12-31'::date) every ('1 day'::interval),
default partition default_p
);

every:指定跨越基数

执行结果显示

testDB=# create table public.test_partition_every(
testDB(#   id numeric,
testDB(#   name character varying(32),
testDB(#   dw_end_date date
testDB(# ) distributed by(id)
testDB-# partition by range(dw_end_Date)
testDB-# (
testDB(#   partition p202012 start('2020-12-1'::date) end ('2020-12-31'::date)
testDB(#   every ('1 days'::interval)
testDB(# );
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_1" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_2" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_3" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_4" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_5" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_6" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_7" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_8" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_9" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_10" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_11" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_12" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_13" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_14" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_15" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_16" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_17" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_18" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_19" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_20" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_21" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_
8000
1_prt_p202012_22" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_23" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_24" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_25" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_26" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_27" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_28" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_29" for table "test_partition_every"
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p202012_30" for table "test_partition_every"
CREATE TABLE

list 分区

根据值的分组,相同的数据归类到一组,也就一个分区中
create table public.test_partition_list(
member_id numeric,
city character varying(32)
)distributed by (member_id)
partition by list(city)
(
partition guangzhou values('guangzhou'),
partition hangzhou values('hangzhou'),
default partition other_city
);

create table test_partition_list
(
id int,
name varchar(64),
fdate varchar(10)
)
distributed by (id)
partition by list (fdate)
(
partition p1 values ('2017-01-01', '2017-01-02'),
partition p2 values ('2017-01-03'),
default partition pd
);

执行结果显示

testDB=# create table test_partition_range
testDB-# (
testDB(#     id int,
testDB(#     name varchar(64),
testDB(#     fdate varchar(64)
testDB(#     ) distributed by (id)
testDB-#     partition by range(fdate)
testDB-#     (
testDB(#         partition p1 start ('2017-01-01') inclusive end ('2017-01-31') exclusive,
testDB(#         partition p2 start ('2017-02-01') inclusive end ('2017-02-29') exclusive,
testDB(#         default partition default_p
testDB(#     );
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_default_p" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p1" for table "test_partition_range"
NOTICE:  CREATE TABLE will create partition "test_partition_range_1_prt_p2" for table "test_partition_range"
CREATE TABLE

修改分区表语法

ALTER DEFAULT PARTITION
DROP DEFAULT PARTITION [IF EXISTS]
DROP PARTITION [IF EXISTS] {
partition_name
| FOR (RANK(number))
| FOR (value)
}
[CASCADE]
TRUNCATE DEFAULT PARTITION
TRUNCATE PARTITION {
partition_name
| FOR (RANK(number))
| FOR (value)
}
RENAME DEFAULT PARTITION TO new_partition_name
RENAME PARTITION {
partition_name
| FOR (RANK(number))
| FOR (value)
}
TO new_partition_name
ADD DEFAULT PARTITION NAME [(subpartition_spec)]
ADD PARTITION [name] partition_element
[(subpartition_spec)]
EXCHANGE PARTITION {
partition_name
| FOR (RANK(number))
| FOR (value)
} WITH TABLE TABLE_NAME
[WITH|WITHOUT VALIDATION]
EXCHANGE EFAULT PARTITION WITH TABLE TABLE_NAME
[WITH|WITHOUT VALIDATION]
SET SUBPARTITION TEMPLATE (subpartition_spec)
SPLIT DEFAULT PARTITION {
AT (list_value)
|START([datatype] range_value) [INCLUSIVE|EXCLUSIVE]
END ([datatype]) range_value) [INCLUSIVE|EXCLUSIVE]
}
[INTO (PARTITION new_partition_name,
PARTITION default_partition_name)]
SPLIT DPARTITION {
partition_name
| FOR (RANK(number))
| FOR (value)
} AT(value)
[INTO (PARTITION partition_name, PARTITION partition_name]

新增分区表/drop分区表/truncate分区表

alter table public.test_partition_every add partition p20210205_6 start ('2012-02-05'::date) END ('2012-01-07'::date);

alter table public.test_partition_every drop partition p20120105_6;

alter table public.test_partition_every truncate partition p20120205_6;

添加分区操作步骤

testDB=# alter table public.test_partition_every add partition p20210105_6 start ('2012-01-05'::date) END ('2012-01-07'::date);
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p20210105_6" for table "test_partition_every"
ALTER TABLE
testDB=# select gp_segment_id,tableoid::regclass,count(*) from test_partition_every group by 1,2 order by 1,2;
gp_segment_id | tableoid | count
---------------+----------+-------
(0 rows)

testDB=# \d+ public.test_partition_every
Table "public.test_partition_every"
Column    |         Type          | Modifiers | Storage  | Stats target | Description
-------------+-----------------------+-----------+----------+--------------+-------------
id          | numeric               |           | main     |              |
name        | character varying(32) |           | extended |              |
dw_end_date | date                  |           | plain    |              |
Child tables: test_partition_every_1_prt_p202012_1,
test_partition_every_1_prt_p202012_10,
test_partition_every_1_prt_p202012_11,
test_partition_every_1_prt_p202012_12,
test_partition_every_1_prt_p202012_13,
test_partition_every_1_prt_p202012_14,
test_partition_every_1_prt_p202012_15,
test_partition_every_1_prt_p202012_16,
test_partition_every_1_prt_p202012_17,
test_partition_every_1_prt_p202012_18,
test_partition_every_1_prt_p202012_19,
test_partition_every_1_prt_p202012_2,
test_partition_every_1_prt_p202012_20,
test_partition_every_1_prt_p202012_21,
test_partition_every_1_prt_p202012_22,
test_partition_every_1_prt_p202012_23,
test_partition_every_1_prt_p202012_24,
test_partition_every_1_prt_p202012_25,
test_partition_every_1_prt_p202012_26,
test_partition_every_1_prt_p202012_27,
test_partition_every_1_prt_p202012_28,
test_partition_every_1_prt_p202012_29,
test_partition_every_1_prt_p202012_3,
test_partition_every_1_prt_p202012_30,
test_partition_every_1_prt_p202012_31,
test_partition_every_1_prt_p202012_32,
test_partition_every_1_prt_p202012_33,
test_partition_every_1_prt_p202012_34,
test_partition_every_1_prt_p202012_35,
test_partition_every_1_prt_p202012_36,
test_partition_every_1_prt_p202012_37,
test_partition_every_1_prt_p202012_38,
test_partition_every_1_prt_p202012_39,
test_partition_every_1_prt_p202012_4,
test_partition_every_1_prt_p202012_40,
test_partition_every_1_prt_p202012_41,
test_partition_every_1_prt_p202012_42,
test_partition_every_1_prt_p202012_43,
test_partition_every_1_prt_p202012_44,
test_partition_every_1_prt_p202012_45,
test_partition_every_1_prt_p202012_46,
test_partition_every_1_prt_p202012_47,
test_partition_every_1_prt_p202012_48,
test_partition_every_1_prt_p202012_49,
test_partition_every_1_prt_p202012_5,
test_partition_every_1_prt_p202012_50,
test_partition_every_1_prt_p202012_51,
test_partition_every_1_prt_p202012_52,
test_partition_every_1_prt_p202012_53,
test_partition_every_1_prt_p202012_54,
test_partition_every_1_prt_p202012_55,
test_partition_every_1_prt_p202012_56,
test_partition_every_1_prt_p202012_57,
test_partition_every_1_prt_p202012_58,
test_partition_every_1_prt_p202012_59,
test_partition_every_1_prt_p202012_6,
test_partition_every_1_prt_p202012_60,
test_partition_every_1_prt_p202012_61,
test_partition_every_1_prt_p202012_7,
test_partition_every_1_prt_p202012_8,
test_partition_every_1_prt_p202012_9,
test_partition_every_1_prt_p20210105_6
Distributed by: (id)
Partition by: (dw_end_date)

testDB=# alter table public.test_partition_every drop partition p20210105_6;
ALTER TABLE
testDB=# alter table public.test_partition_every add partition p20210205_6 start ('2012-02-05'::date) END ('2012-01-07'::date);
ERROR:  START greater than END for partition "p20210205_6"
testDB=# alter table public.test_partition_every add partition p20210205_6 start ('2012-02-05'::date) END ('2012-02-07'::date);
NOTICE:  CREATE TABLE will create partition "test_partition_every_1_prt_p20210205_6" for table "test_partition_every"
ALTER TABLE

testDB=# \d+  public.test_partition_every
Table "public.test_partition_every"
Column    |         Type          | Modifiers | Storage  | Stats target | Description
-------------+-----------------------+-----------+----------+--------------+-------------
id          | numeric               |           | main     |              |
name        | character varying(32) |           | extended |              |
dw_end_date | date                  |           | plain    |              |
Child tables: test_partition_every_1_prt_p202012_1,
test_partition_every_1_prt_p202012_10,
test_partition_every_1_prt_p202012_11,
test_partition_every_1_prt_p202012_12,
test_partition_every_1_prt_p202012_13,
test_partition_every_1_prt_p202012_14,
test_partition_every_1_prt_p202012_15,
test_partition_every_1_prt_p202012_16,
test_partition_every_1_prt_p202012_17,
test_partition_every_1_prt_p202012_18,
test_partition_every_1_prt_p202012_19,
test_partition_every_1_prt_p202012_2,
test_partition_every_1_prt_p202012_20,
test_partition_every_1_prt_p202012_21,
test_partition_every_1_prt_p202012_22,
test_partition_every_1_prt_p202012_23,
test_partition_every_1_prt_p202012_24,
test_partition_every_1_prt_p202012_25,
test_partition_every_1_prt_p202012_26,
test_partition_every_1_prt_p202012_27,
test_partition_every_1_prt_p202012_28,
test_partition_every_1_prt_p202012_29,
test_partition_every_1_prt_p202012_3,
test_partition_every_1_prt_p202012_30,
test_partition_every_1_prt_p202012_31,
test_partition_every_1_prt_p202012_32,
test_partition_every_1_prt_p202012_33,
test_partition_every_1_prt_p202012_34,
test_partition_every_1_prt_p202012_35,
test_partition_every_1_prt_p202012_36,
test_partition_every_1_prt_p202012_37,
test_partition_every_1_prt_p202012_38,
test_partition_every_1_prt_p202012_39,
test_partition_every_1_prt_p202012_4,
test_partition_every_1_prt_p202012_40,
test_partition_every_1_prt_p202012_41,
test_partition_every_1_prt_p202012_42,
test_partition_every_1_prt_p202012_43,
test_partition_every_1_prt_p202012_44,
test_partition_every_1_prt_p202012_45,
test_partition_every_1_prt_p202012_46,
test_partition_every_1_prt_p202012_47,
test_partition_every_1_prt_p202012_48,
test_partition_every_1_prt_p202012_49,
test_partition_every_1_prt_p202012_5,
test_partition_every_1_prt_p202012_50,
test_partition_every_1_prt_p202012_51,
test_partition_every_1_prt_p202012_52,
test_partition_every_1_prt_p202012_53,
test_partition_every_1_prt_p202012_54,
test_partition_every_1_prt_p202012_55,
test_partition_every_1_prt_p202012_56,
test_partition_every_1_prt_p202012_57,
test_partition_every_1_prt_p202012_58,
test_partition_every_1_prt_p202012_59,
test_partition_every_1_prt_p202012_6,
test_partition_every_1_prt_p202012_60,
test_partition_every_1_prt_p202012_61,
test_partition_every_1_prt_p202012_7,
test_partition_every_1_prt_p202012_8,
test_partition_every_1_prt_p202012_9,
test_partition_every_1_prt_p20210205_6
Distributed by: (id)
Partition by: (dw_end_date)

truncate 只会清理,不会删除
testDB=# alter table public.test_partition_every truncate partition p20210205_6;
ALTER TABLE
testDB=#

testDB=# \d+ public.test_partition_every
Table "public.test_partition_every"
Column    |         Type          | Modifiers | Storage  | Stats target | Description
-------------+-----------------------+-----------+----------+--------------+-------------
id          | numeric               |           | main     |              |
name        | character varying(32) |           | extended |              |
dw_end_date | date                  |           | plain    |              |
Child tables: test_partition_every_1_prt_p202012_1,
test_partition_every_1_prt_p202012_10,
test_partition_every_1_prt_p202012_11,
test_partition_every_1_prt_p202012_12,
test_partition_every_1_prt_p202012_13,
test_partition_every_1_prt_p202012_14,
test_partition_every_1_prt_p202012_15,
test_partition_every_1_prt_p202012_16,
test_partition_every_1_prt_p202012_17,
test_partition_every_1_prt_p202012_18,
test_partition_every_1_prt_p202012_19,
test_partition_every_1_prt_p202012_2,
test_partition_every_1_prt_p202012_20,
test_partition_every_1_prt_p202012_21,
test_partition_every_1_prt_p202012_22,
test_partition_every_1_prt_p202012_23,
test_partition_every_1_prt_p202012_24,
test_partition_every_1_prt_p202012_25,
test_partition_every_1_prt_p202012_26,
test_partition_every_1_prt_p202012_27,
test_partition_every_1_prt_p202012_28,
test_partition_every_1_prt_p202012_29,
test_partition_every_1_prt_p202012_3,
test_partition_every_1_prt_p202012_30,
test_partition_every_1_prt_p202012_31,
test_partition_every_1_prt_p202012_32,
test_partition_every_1_prt_p202012_33,
test_partition_every_1_prt_p202012_34,
test_partition_every_1_prt_p202012_35,
test_partition_every_1_prt_p202012_36,
test_partition_every_1_prt_p202012_37,
test_partition_every_1_prt_p202012_38,
test_partition_every_1_prt_p202012_39,
test_partition_every_1_prt_p202012_4,
test_partition_every_1_prt_p202012_40,
test_partition_every_1_prt_p202012_41,
test_partition_every_1_prt_p202012_42,
test_partition_every_1_prt_p202012_43,
test_partition_every_1_prt_p202012_44,
test_partition_every_1_prt_p202012_45,
test_partition_every_1_prt_p202012_46,
test_partition_every_1_prt_p202012_47,
test_partition_every_1_prt_p202012_48,
test_partition_every_1_prt_p202012_49,
test_partition_every_1_prt_p202012_5,
test_partition_every_1_prt_p202012_50,
test_partition_every_1_prt_p202012_51,
test_partition_every_1_prt_p202012_52,
test_partition_every_1_prt_p202012_53,
test_partition_every_1_prt_p202012_54,
test_partition_every_1_prt_p202012_55,
test_partition_every_1_prt_p202012_56,
test_partition_every_1_prt_p202012_57,
test_partition_every_1_prt_p202012_58,
test_partition_every_1_prt_p202012_59,
test_partition_every_1_prt_p202012_6,
test_partition_every_1_prt_p202012_60,
test_partition_every_1_prt_p202012_61,
test_partition_every_1_prt_p202012_7,
test_partition_every_1_prt_p202012_8,
test_partition_every_1_prt_p202012_9,
test_partition_every_1_prt_p20210205_6
Distributed by: (id)
Partition by: (dw_end_date)

testDB=#

交换分区

不太熟悉

分区split

切割普通分区:
将分区p2 在 '2017-02-20' 左右切分成两块
alter table test_partition_range split partition p2 at ('2017-02-20') into (partition p2, partition p3);

切割默认分区:
alter table test_partition_range split default partition start ('2017-03-01')  end ('2017-03-31')  into (partition p4, default partition);

子分区创建与操作

在GPDB中,分区是可以嵌套增加的,分区下面可以有子分区

create table test_partition_range_2
(
id int,
name varchar(64),
fdate varchar(10)
)
distributed by (id)
partition by range(fdate)
subpartition by list(name)
subpartition template
(
subpartition c1 values ('xiaoxiao'),
subpartition c2 values ('xiaohua')
)
(
partition p1 start ('2017-01-01') end ('2017-01-31')
)
上面的分区中,p1会再分两个c1/c2子分区

truncate 子分区

alter table test_partition_range_2 alter partition p1 truncate partition c2;

drop 子分区

alter table test_partition_range_2 alter partition p1 drop partition c2;

写的不错的博客

https://blog.51cto.com/u_13126942/2053712
https://www.cnblogs.com/kingle-study/p/10550987.html

参考文档

http://greenplum.org/docs/510/ref_guide/sql_commands/ALTER_TABLE.html

http://www.dbaref.com/choosing-the-table-storage-model-in-greenplum

https://github.com/digoal/blog/blob/master/201708/20170817_01.md
https://github.com/digoal/blog/blob/master/201708/20170817_03.md
https://github.com/digoal/blog/blob/master/201708/20170818_02.md
https://github.com/digoal/blog/blob/master/201607/20160719_02.md
https://github.com/digoal/blog/blob/master/201711/20171123_01.md

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: