td 字典表_TD常用字典视图在GaussDB(DWS)上实现

TD有一些常用的字典视图,可能会在迁移TD的过程中脚本使用到,而且客户会更习惯使用TD的字典表,在过渡过程中建一个TD的视图字典表能够让客户更加容易上手GaussDB(DWS).附件有代码,可以直接拿去部署,但需要建一个dbc schema,同时赋予到public的角色。

TD主要的字典视图有:

字典名称

描述

GaussDB(DWS)替换视图

DBC.TABLESV

表、视图、函数等对象信息

pg_tables pg_views

DBC.COLUMNSV

表的字段信息

pg_attribute

DBC.TABLESIZEV

表的空间大小信息

pg_tables

DBC.STATSV

表的统计信息内容

pg_statistic

实现方式:

主要使用现有的DWS字典,查看TD字典所需的内容信息怎么样获取,然后再通过多表关联获取全部信息。类似DBC.TABELESV里面有很多是TD自己的信息,而且那些信息在GaussDB(DWS)无法获取,因此在视图中直接不显示。同时增加了DWS常用的字段,例如oid,分布列,分布方式等。

实现代码示例如下:

drop view dbc.tablesv;

create or replace view dbc.tablesv

as

select pn.nspname as databasename

,pc.relname as tablename

,case pc.relkind when 'r' then 't' when 'f' then 'ft' else pc.relkind end as tablekind

,case when (relkind = 'r' and getdistributekey(pc.oid) is not null) or relkind = 'f' then pg_get_tabledef(pc.oid) when relkind = 'v' then pg_get_viewdef(pc.oid) else '' end as RequestText

,pg_get_userbyid(pc.relowner) as CreatorName

,description as CommentString

,po.ctime as CreateTimestamp

,po.mtime as LastAlterTimeStamp

,case when pc.relkind = 'r' then array_length(string_to_array(getdistributekey(pc.oid),','),1) else 0 end as PIColumnCount

,ppt.partcnt as PartitioningLevels

,pn.oid as SchemaOid

,pc.oid as TableOid

,case when pc.relkind = 'r' then getdistributekey(pc.oid) else null end as DistributeKey

,replace(reloptions[1],'orientation=','') orientation

,replace(reloptions[array_upper(reloptions,1)],'compression=','') as compression

from pg_class pc

inner join pg_namespace pn

on pc.relnamespace = pn.oid

and pc.relkind in ('r','f','v')

and pc.oid > 16384

and pn.oid not in (100)

left join pg_description pd

on pc.oid = pd.objoid

and objsubid = 0

left join pg_object po

on pc.oid = po.object_oid

left join (select parentid,count(*) partcnt from pg_partition where parttype = 'p' group by 1) ppt

on pc.oid = ppt.parentid

;

查询结果如下:

其他的代码此处不一一展示,请见附件查看。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值