lightdb-a 分区表支持nocompress compress关键字

概述

在信创移植DDL SQL语句中,有来源于Oracle数据库的SQL语句。

在Oracle中,创建分区表时,可以为每个分区显示的指定nocompress/compress关键字,分别表示不压缩/压缩,一般不显示指定时默认为nocompress状态。

LightDB-a在23.3版本中创建分区表对nocompress compress关键字做了支持,来保证DDL语句正常执行,减少业务移植难度,降低业务移植成本。

案例演示

环境准备

进入psql交互界面执行如下命令:

create database test_oracle lightdb_syntax_compatible_type oracle;
\c test_oracle

List分区

创建List分区

CREATE TABLE lt_oracle_partition_list1
(
    a int,
    b float,
    c date,
    d timestamp,
    e char(10)
) PARTITION BY LIST(e)
(
    PARTITION p1 VALUES ('0001', '0002', '0003', '0004', '0005') compress,
    PARTITION p2 VALUES ('0006', '0007', '0008', '0009') nocompress,
    PARTITION p3 VALUES ('0010', '0011')
) distributed by (a);

查看分区情况

test_oracle=# \d+ lt_oracle_partition_list1
                             Partitioned table "public.lt_oracle_partition_list1"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | date                        |           |          |         | plain    |              | 
 d      | timestamp without time zone |           |          |         | plain    |              | 
 e      | character(10)               |           |          |         | extended |              | 
Partition key: LIST (e)
Partitions: lt_oracle_partition_list1_1_prt_p1 FOR VALUES IN ('0001      ', '0002      ', '0003      ', '0004      ', '0005      '),
            lt_oracle_partition_list1_1_prt_p2 FOR VALUES IN ('0006      ', '0007      ', '0008      ', '0009      '),
            lt_oracle_partition_list1_1_prt_p3 FOR VALUES IN ('0010      ', '0011      ')
Distributed by: (a)
Access method: heap

Range分区

创建Range分区

CREATE TABLE lt_oracle_interval1
(
    a int,
    b float,
    c date,
    d timestamp,
    e char(10)
)PARTITION BY RANGE (c)
(
        PARTITION p1 VALUES LESS THAN(to_date('2020-01-01', 'yyyy-mm-dd')) nocompress,
        PARTITION p2 VALUES LESS THAN(to_date('2021-01-01', 'yyyy-mm-dd')) compress,
        PARTITION p3 VALUES LESS THAN(to_date('2022-01-01', 'yyyy-mm-dd'))
) distributed by (a);

查看分区情况

test_oracle=# \d+ lt_oracle_interval1
                                Partitioned table "public.lt_oracle_interval1"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | date                        |           |          |         | plain    |              | 
 d      | timestamp without time zone |           |          |         | plain    |              | 
 e      | character(10)               |           |          |         | extended |              | 
Partition key: RANGE (c)
Partitions: lt_oracle_interval1_1_prt_p1 FOR VALUES FROM (MINVALUE) TO ('2020-01-01'),
            lt_oracle_interval1_1_prt_p2 FOR VALUES FROM ('2020-01-01') TO ('2021-01-01'),
            lt_oracle_interval1_1_prt_p3 FOR VALUES FROM ('2021-01-01') TO ('2022-01-01')
Distributed by: (a)
Access method: heap

Hash分区

创建分区

CREATE TABLE lt_oracle_partition_hash1
(
    a int,
    b float,
    c VARCHAR(20),
    d DATE,
    e timestamp
) PARTITION BY HASH (a)
(
	PARTITION p1,
    PARTITION p2 compress,
	PARTITION p3 nocompress
) distributed by (a);

查看分区情况

test_oracle=# \d+ lt_oracle_partition_hash1
                             Partitioned table "public.lt_oracle_partition_hash1"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | character varying(20)       |           |          |         | extended |              | 
 d      | date                        |           |          |         | plain    |              | 
 e      | timestamp without time zone |           |          |         | plain    |              | 
Partition key: HASH (a)
Partitions: lt_oracle_partition_hash1_1_prt_p1 FOR VALUES WITH (modulus 3, remainder 0),
            lt_oracle_partition_hash1_1_prt_p2 FOR VALUES WITH (modulus 3, remainder 1),
            lt_oracle_partition_hash1_1_prt_p3 FOR VALUES WITH (modulus 3, remainder 2)
Distributed by: (a)
Access method: heap


Range + List分区

创建分区

CREATE TABLE lt_oracle_rl3
(
    a int,
    b float,
    c varchar(20),
    d date,
    e timestamp
) PARTITION BY RANGE(a)
SUBPARTITION BY LIST (b)
SUBPARTITION TEMPLATE
(
    SUBPARTITION p1 VALUES (1.1, 2.1, 3.1) COMPRESS ,
    SUBPARTITION p2 VALUES (4.1) NOCOMPRESS
)
(
    PARTITION p1 VALUES LESS THAN(10) COMPRESS ,
    PARTITION p2 VALUES LESS THAN(20) NOCOMPRESS ,
    PARTITION p3 VALUES LESS THAN(30)
) distributed by (a);

查看分区情况

test_oracle=# \d+ lt_oracle_rl3
                                   Partitioned table "public.lt_oracle_rl3"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | character varying(20)       |           |          |         | extended |              | 
 d      | date                        |           |          |         | plain    |              | 
 e      | timestamp without time zone |           |          |         | plain    |              | 
Partition key: RANGE (a)
Partitions: lt_oracle_rl3_1_prt_p1 FOR VALUES FROM (MINVALUE) TO (10), PARTITIONED,
            lt_oracle_rl3_1_prt_p2 FOR VALUES FROM (10) TO (20), PARTITIONED,
            lt_oracle_rl3_1_prt_p3 FOR VALUES FROM (20) TO (30), PARTITIONED
Distributed by: (a)
Access method: heap

test_oracle=# \d+ lt_oracle_rl3_1_prt_p1
                               Partitioned table "public.lt_oracle_rl3_1_prt_p1"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | character varying(20)       |           |          |         | extended |              | 
 d      | date                        |           |          |         | plain    |              | 
 e      | timestamp without time zone |           |          |         | plain    |              | 
Partition of: lt_oracle_rl3 FOR VALUES FROM (MINVALUE) TO (10)
Partition constraint: ((a IS NOT NULL) AND (a < 10))
Partition key: LIST (b)
Partitions: lt_oracle_rl3_1_prt_p1_2_prt_p1 FOR VALUES IN ('1.1', '2.1', '3.1'),
            lt_oracle_rl3_1_prt_p1_2_prt_p2 FOR VALUES IN ('4.1')
Distributed by: (a)
Access method: heap

test_oracle=# \d+ lt_oracle_rl3_1_prt_p2
                               Partitioned table "public.lt_oracle_rl3_1_prt_p2"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | character varying(20)       |           |          |         | extended |              | 
 d      | date                        |           |          |         | plain    |              | 
 e      | timestamp without time zone |           |          |         | plain    |              | 
Partition of: lt_oracle_rl3 FOR VALUES FROM (10) TO (20)
Partition constraint: ((a IS NOT NULL) AND (a >= 10) AND (a < 20))
Partition key: LIST (b)
Partitions: lt_oracle_rl3_1_prt_p2_2_prt_p1 FOR VALUES IN ('1.1', '2.1', '3.1'),
            lt_oracle_rl3_1_prt_p2_2_prt_p2 FOR VALUES IN ('4.1')
Distributed by: (a)
Access method: heap

test_oracle=# \d+ lt_oracle_rl3_1_prt_p3
                               Partitioned table "public.lt_oracle_rl3_1_prt_p3"
 Column |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 a      | integer                     |           |          |         | plain    |              | 
 b      | double precision            |           |          |         | plain    |              | 
 c      | character varying(20)       |           |          |         | extended |              | 
 d      | date                        |           |          |         | plain    |              | 
 e      | timestamp without time zone |           |          |         | plain    |              | 
Partition of: lt_oracle_rl3 FOR VALUES FROM (20) TO (30)
Partition constraint: ((a IS NOT NULL) AND (a >= 20) AND (a < 30))
Partition key: LIST (b)
Partitions: lt_oracle_rl3_1_prt_p3_2_prt_p1 FOR VALUES IN ('1.1', '2.1', '3.1'),
            lt_oracle_rl3_1_prt_p3_2_prt_p2 FOR VALUES IN ('4.1')
Distributed by: (a)
Access method: heap



增加分区

创建并增加分区

create table tt6(id int)
PARTITION by range(id)(
    partition t1 VALUES LESS THAN (202000) nocompress,
    partition t2 VALUES LESS THAN (202001) compress,
    partition t3 VALUES LESS THAN (202002)
) distributed by (id);

alter table tt6 add partition t4 values less than (202003) nocompress;
alter table tt6 add partition t5 values less than (202004) compress;
alter table tt6 add partition t6 values less than (202005) ;

查看分区

test_oracle=# \d+ tt6
                              Partitioned table "public.tt6"
 Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
--------+---------+-----------+----------+---------+---------+--------------+-------------
 id     | integer |           |          |         | plain   |              | 
Partition key: RANGE (id)
Partitions: tt6_1_prt_t1 FOR VALUES FROM (MINVALUE) TO (202000),
            tt6_1_prt_t2 FOR VALUES FROM (202000) TO (202001),
            tt6_1_prt_t3 FOR VALUES FROM (202001) TO (202002),
            tt6_1_prt_t4 FOR VALUES FROM (202002) TO (202003),
            tt6_1_prt_t5 FOR VALUES FROM (202003) TO (202004),
            tt6_1_prt_t6 FOR VALUES FROM (202004) TO (202005)
Distributed by: (id)
Access method: heap

结论

在LightDB23.3版本中,创建分区表可以添加nocompress、compress关键字,并正常执行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值