greenplum建表策略详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/double_happiness/article/details/83275055

建表语法:

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;

猜你喜欢

转载自blog.csdn.net/double_happiness/article/details/83275055
今日推荐