【发布时间】:2017-09-11 04:37:31
【问题描述】:
我想在 Greeplum 中创建一个多级分区表,第一级分区为一年,第二级为每 7 天。当我硬编码它工作正常。以下是代码:
DROP TABLE if exists pd.is_it_working;
CREATE TABLE pd.is_it_working
(
ts timestamp without time zone,
client_uname text
)
WITH (APPENDONLY=true,
OIDS=FALSE
)
DISTRIBUTED BY (client_uname)
PARTITION BY RANGE(ts)
SUBPARTITION BY RANGE (ts)
SUBPARTITION TEMPLATE
(
START ('2015-06-01 00:00:00'::timestamp without time zone)INCLUSIVE
END ('2016-01-01 00:00:00'::timestamp without time zone) EXCLUSIVE
EVERY ('1 week'::interval)
WITH (appendonly=true, orientation=parquet, compresstype=snappy, pagesize=1048576, rowgroupsize=8388608),
DEFAULT SUBPARTITION outlying_week
WITH (appendonly=true, orientation=parquet, compresstype=snappy, pagesize=1048576, rowgroupsize=8388608)
)
(
START ('2015-06-01 00:00:00'::timestamp without time zone)INCLUSIVE
END ('2016-01-01 00:00:00'::timestamp without time zone) EXCLUSIVE
EVERY ('1 year'::interval)
WITH (appendonly=true, orientation=parquet, compresstype=snappy, pagesize=1048576, rowgroupsize=8388608),
DEFAULT PARTITION outlying_year
WITH (appendonly=true, orientation=parquet, compresstype=snappy, pagesize=1048576, rowgroupsize=8388608)
)
;
ALTER TABLE pd.is_it_working
OWNER TO pdugar;
现在,问题是如何添加更多分区(例如 2016-2017 年的分区)以及随后的 7 天分区? 如果我有默认分区,则无法添加分区。如果我决定拆分默认分区,它不应该为空,否则我无法对其进行分区。此外,即使它不是空的,如果我拆分它,它将遵循上面定义的子分区模板,这对于新的一年是错误的,应该有一个新的子分区模板,即假设 2016-2017 年的子分区必须他们之间每隔 7 天!
当数据进入时,我必须在此表中动态创建一个新年分区(及其后续子分区),但我无法做到。我还需要在“时间戳”上进行分区。 有什么办法吗?
谢谢
【问题讨论】:
-
DISTRIBUTED BY对 Postgres 无效 - 您真的在使用哪个 DBMS? -
我正在使用基于 postgresql 的关键 greenplum 数据库。
标签: sql ddl database-partitioning greenplum