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)