我有一个表结构,我想按时间戳在一天的范围内进行分区。
它由两个具有共同字段的表组成,为简单起见,我将使用表A,B的示例,如下所示:
create table A (
id serial not null,
ts timestamp without time zone not null,
name text,
some_custom_A_field_1 numeric,
some_custom_A_field_2 numeric
);
create table B (
id serial not null,
ts timestamp without time zone not null,
name text,
some_custom_B_field_1 numeric,
some_custom_B_field_2 numeric,
some_custom_B_field_3 numeric,
some_custom_B_field_4 numeric
);
所以我有两个选择,我不确定哪个是首选。
选项1-创建基表,继承子分区:
create table Base (
id serial not null,
ts timestamp without time zone not null,
name text
)
create table ABase (
some_custom_A_field_1 numeric,
some_custom_A_field_2 numeric
)INHERITS (Base );
create table BBase (
some_custom_B_field_1 numeric,
some_custom_B_field_2 numeric,
some_custom_B_field_3 numeric,
some_custom_B_field_4 numeric
)INHERITS (Base );
CREATE TABLE a_2018_06_24 (CHECK (ts >= '2018-06-24 00:00:00' AND ts < '2018-06-25 00:00:00')) INHERITS (ABase);
CREATE TABLE b_2018_06_24 (CHECK (ts >= '2018-06-24 00:00:00' AND ts < '2018-06-25 00:00:00')) INHERITS (BBase);
选项2-两个基本表已分区:
create table ABase (
id serial not null,
ts timestamp without time zone not null,
name text,
some_custom_A_field_1 numeric,
some_custom_A_field_2 numeric
);
create table BBase (
id serial not null,
ts timestamp without time zone not null,
name text,
some_custom_B_field_1 numeric,
some_custom_B_field_2 numeric,
some_custom_B_field_3 numeric,
some_custom_B_field_4 numeric
);
CREATE TABLE a_2018_06_24 (CHECK (ts >= '2018-06-24 00:00:00' AND ts < '2018-06-25 00:00:00')) INHERITS (ABase);
CREATE TABLE b_2018_06_24 (CHECK (ts >= '2018-06-24 00:00:00' AND ts < '2018-06-25 00:00:00')) INHERITS (BBase);
其他信息:
什么是更好的做法,优点/缺点?
谢谢。