存储方法的使用:当sql语句不做指定时,默认使用astore存储引擎,row存储方法
create table test_astore_row(col text) with (orientation=row);
create table test_astore_column(col text) with (orientation=column);
create foreign table test_astore_mot(col int) server mot_server;
create table test_ustore(col text) with (storage_type=ustore);
GBase 8c 需要将数据按照一定规律分布到各个数据节点,目前支持hash分片。
在此基础上,分区表功能,支持二级分区,9种分区组合,interval分区。即分片+分区功能。
分区类型 | 一级分区 | 二级分区 |
---|---|---|
hash | hash | hash-list;hash-hash;hash-range |
range | range | range-range;range-hash;rang-list |
list | list | list-list;list-range;list-hash |
interval分区 | range |
GBase 8c 的数据分片策略:在创建表时,通过关键字distribute、replication来设置表分片策略。
create table t1_dis(c1 int,c2 int) distribute by hash(c1);
crete table t1_rep(c1 int,c2 int) distribute by replication;
在不指定时,默认使用hash分片,分布式键按照顺序为第一个满足hash算法的字段。
interval分区:根据间隔自动创建分区,例如,1 day 、1 month(主备式)
create table sales(
prod_id number(6),
cust_id number,
time_id date,
channel_id char(1),
promo_id number(6),
quantity_sold number(3),
amount_sold number(10,2))
partition by range(time_id) interval('1 day')
(partition p1 values less than ('2019-02-01 00:00:00'),
partition p2 values less than ('2019-02-02 00:00:00')
);
分区自动管理:根据间隔自动创建分区,例如:1 day、1 month(分布式)
create table range_auto_1hour_tb01(id int,ip text,time timestamp) with(PERIOD='1 hour') partition by range(time)
( partition p1 values less than ('2022-11-23 14:00:00'));
GBase 8c 提供了多种索引类型:hash,B-tree,gist,gin。每一种索引类型使用了一种不同的算法来适应不同类型的查询。
hash索引:create index ... using hash(column);
B-tree索引:create index ... using btree(column);
gist索引:create index ... using gist(column);
gin索引:create index ... using gin(column);
create table test_row_compress(col text) with (compress_type = 2,COMPRESS_LEVEL = 3);
compress_type: 行存表参数,设置行存表压缩算法。1代表pglz算法,2代表zstd算法,默认不压缩(仅支持ASTORE下的普通表) 取值范围:0~2,默认值为0
COMPRESS_LEVEL:行存表参数,设置行存表压缩算法等级,仅当COMPRESS_TYPE为2时生效。压缩等级越高,表的压缩效果越好,表的访问速度越慢(仅支持ASTORE下的普通表)取值范围:-31~31,默认值为0
create table test_compress(col text) with (orientation=column,compression=high);
compression:指定表数据的压缩等级,它决定了表数据的压缩比以及压缩时间。一般来讲,压缩级别越高,压缩比也越大,压缩时间也越长;反之亦然。实际压缩比取决于加载的表数据的分布特征。行存表不支持压缩。取值范围:列存表的有效值为:YES/NO/LOW/MIDDLE/HIGH,默认值为 LOW。
查表大小:
select * from pg_size_pretty(pg_catalog.pg_table_size('test_column_compress'));