pg_depend表里objsubid、refclassid和refohjid几个列的含义看不懂,有人能指教一下么?

具体看:http://www.postgres.cn/docs/9...

pg_depend
pg_depend表记录数据库对象之间的依赖关系。 这个信息允许DROP命令找出哪些其它对象必须由DROP CASCADE删除, 或者是在DROP RESTRICT的情况下避免删除。

这个表的功能类似pg_shdepend, 用于记录那些在数据库集群之间共享的对象之间的依赖性关系。

表 48-18. pg_depend 字段

名字 类型 引用 描述
classid oid pg_class.oid 有依赖对象所在系统表的 OID
objid oid 任意 OID 属性 指定的依赖对象的 OID
objsubid int4 对于表字段,这个是该属性的字段数(objid和classid 引用表本身)。对于所有其它对象类型,目前这个字段是零。
refclassid oid pg_class.oid 被引用对象所在的系统表的 OID
refobjid oid 任意 OID 属性 指定的被引用对象的 OID
refobjsubid int4 对于表字段,这个是该字段的字段号(refobjid和refclassid 引用表本身)。对于所有其它对象类型,目前这个字段是零。
deptype char 一个定义这个依赖关系特定语义的代码。见下文。

http://www.postgres.cn/docs/9...

阅读 3.3k
1 个回答

参考

pg-depend

个人理解

  • objid对象是refobjid对象的一部分
  • refobjid对象中用到了objid对象

例子解析

test_db=# \d+ t_id
                                    Table "public.t_id"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
 id     | integer |           |          |         | plain    |              |
 name   | text    |           |          |         | extended |              |


select classid::regclass,objid,objid::regclass,objsubid::regclass,refclassid::regclass,refobjid,refobjid::regclass,
deptype
from pg_depend
where refobjid='t_id'::regclass  ;
 classid  | objid |          objid          | objsubid | refclassid | refobjid | refobjid | deptype
----------+-------+-------------------------+----------+------------+----------+----------+---------
 pg_type  | 17820 | 17820                   | -        | pg_class   |    17818 | t_id     | i
 pg_class | 17821 | pg_toast.pg_toast_17818 | -        | pg_class   |    17818 | t_id     | i
 
 -- 解释 refobjid 在refclassid对应记录的条目位置
 test_db=# select relname,oid,relfilenode from pg_class where oid=17818;
 relname |  oid  | relfilenode
---------+-------+-------------
 t_id    | 17818 |       17818
(1 row)

 -- 解释 objid 在classid对应记录的条目位置
 test_db=# select relname,oid,relfilenode from pg_class where oid=17821;
    relname     |  oid  | relfilenode
----------------+-------+-------------
 pg_toast_17818 | 17821 |       17821
(1 row)

test_db=# select * from pg_type where oid=17820;
-[ RECORD 1 ]--+------------
typname        | t_id
typnamespace   | 2200
typowner       | 10
typlen         | -1
typbyval       | f
typtype        | c
typcategory    | C
typispreferred | f
typisdefined   | t
typdelim       | ,
typrelid       | 17818
typelem        | 0
typarray       | 17819
typinput       | record_in
typoutput      | record_out
typreceive     | record_recv
typsend        | record_send
typmodin       | -
typmodout      | -
typanalyze     | -
typalign       | d
typstorage     | x
typnotnull     | f
typbasetype    | 0
typtypmod      | -1
typndims       | 0
typcollation   | 0
typdefaultbin  |
typdefault     |
typacl         |
 
推荐问题
宣传栏