greenplum建表策略詳解
阿新 • • 發佈:2018-12-03
建表語法:
CREATE [[GLOBAL | LOCAL] {TEMPORARY | TEMP}] TABLE table_name ( [ { column_name data_type [ DEFAULT default_expr ] [column_constraint [ ... ] [ ENCODING ( storage_directive [,...] ) ] ] | table_constraint | LIKE other_table [{INCLUDING | EXCLUDING} {DEFAULTS | CONSTRAINTS}] ...} [, ... ] ] [column_reference_storage_directive [, ... ] ) [ INHERITS ( parent_table [, ... ] ) ] [ WITH ( storage_parameter=value [, ... ] ) [ ON COMMIT {PRESERVE ROWS | DELETE ROWS | DROP} ] [ TABLESPACE tablespace ] [ DISTRIBUTED BY (column, [ ... ] ) | DISTRIBUTED RANDOMLY ] [ 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) ] )
普通heap表
CREATE TABLE test(
id int,
num int
)
distribute by id;
普通AO表
CREATE TABLE test(
id int,
num int
)
with
(appendonly=true)
distribute by id;
AO表壓縮行存
CREATE TABLE test(
id int,
num int
)
with
(appendonly=true,compresslevel=5)
distribute by id;
AO表壓縮列存
CREATE TABLE test( id int, num int ) with (appendonly=true, orientation=column,compresslevel=5) distribute by id;
AO表列存壓縮儲存
CREATE TABLE test(
id int,
num int
)
with
(appendonly=true, orientation=column,compresstype=zlib,compresslevel=5)
distribute by id;
--compresslevel:取值為1~9,一般取5即可,數值越大壓縮率越高
分割槽表列表分割槽
CREATE TABLE test( id int, sex int, ) with (appendonly=true,compresslevel=5,orientation=true,compresstype=zlib) partition by list(num) ( subpartition man value('m'), subpartition famal value('f'), default subpartition other ) distribute by id;
分割槽表範圍分割槽
--方式一
CREATE TABLE test(
id int,
ts date,
)
with
(appendonly=true,compresslevel=5,orientation=true,compresstype=zlib)
partition by range(ts)
(
start (1) end (31) every(1),
default partition none
)
distribute by id;
--方式二
CREATE TABLE test(
id int,
ts date,
)
with
(appendonly=true,compresslevel=5,orientation=true,compresstype=zlib)
partition by range(ts)
(
partition t1 start('2018-01-09') end ('2018-09-10'),
partition t2 start('2018-09-11') end ('2019-09-10'),
default partition other
)
distribute by id;
--方式三
CREATE TABLE test(
id int,
ts date,
)
with
(appendonly=true,compresslevel=5,orientation=true,compresstype=zlib)
partition by range(ts)
(
start (ts '2018-01-01') inclusive
end (ts '2019-01-01') exclusive
every (interval '7 day')
)
distribute by id;