天天看點

關于greenplum中的appendonly表

    在greenplum裡面有一種appendonly表,隻能insert,不能update、delete的一種表,對于壓縮表跟列存儲來說,前提是必須是appendonly的表。下面介紹appendonly表的一些特性。

1.首先建一張appendonly的表:

aligputf8=# create table cxf_test1 with(appendonly=true,compresslevel=5) as select generate_series(0,1000) a,’helloworld’::varchar(50) b distributed by (a);
SELECT 1001

           

2.查一下表的oid:

aligputf8=# select oid from pg_class where relname=’cxf_test1′;
  oid  
——–
 383660
(1 row)
 
aligputf8=# select oid,oid::regclass from pg_class where relname=’cxf_test1′ or relname like ‘%383660%’;
  oid   |              oid              
——–+——————————–
 383665 | pg_aoseg.pg_aoseg_383660
 383666 | pg_aoseg.pg_aoseg_383660_index
 383660 | cxf_test1
(3 rows)

           

在gp3.3.*的版本裡面,aoseg表的資訊是記錄在pg_class中的relaosegrelid 字段,是以這個為準的

aligputf8=# select relaosegrelid from pg_class where relname=’cxf_test1′;
 relaosegrelid
—————
        383665
(1 row)

           

在gp4.*的版本裡面,pg_class的relaosegrelid 字段已經取消掉了,這個資訊保留在了pg_appendonly表中的segrelid字段中了。

3.aoseg表的字段資訊

aligputf8=# \d pg_aoseg.pg_aoseg_383660
    “pg_aoseg.pg_aoseg_383660″
     Column      |       Type      
—————–+——————
 segno           | integer
 eof             | double precision
 tupcount        | double precision
 varblockcount   | double precision
 eofuncompressed | double precision

           

這個表每個字段的意思gp的文檔裡面沒有,大概覺得每個字段資訊應該是:

Segno: 這個字段還不是很清楚,第一次建表的時候是0,truncate之後就變成1了,再truncate還是1。

eof     :壓縮後檔案大小

tupcount:表的函數

varblockcount:表占用的塊數量

eofuncompressed:未壓縮表的大小

aligputf8=# select * from gp_dist_random(’pg_aoseg.pg_aoseg_383660′);
 segno | eof | tupcount | varblockcount | eofuncompressed
——-+—–+———-+—————+—————–
     0 | 732 |      161 |             1 |            4204
     0 | 728 |      161 |             1 |            4204
     0 | 720 |      159 |             1 |            4152
     0 | 808 |      181 |             1 |            4724
     0 | 796 |      178 |             1 |            4644
     0 | 728 |      161 |             1 |            4204
(6 rows)

           

通過gp_dist_random這個函數,我們可以知道gp底層每個資料節點資料量,資料檔案大小的情況,這樣子我們就能夠分析表的資料分布情況,算出傾斜率等。

基于appendonly表,我開發了兩個gp的函數:

get_table_count是擷取append only表的行數的,appendonly表有一個字段是儲存這些資訊的。這個函數擷取表的函數很快,支援分區表. 

aligputf8=# select * from get_table_count(’rtdc.cxf_test1′);
 get_table_count
—————–
  1001
(1 row)