data_object_id 及 object_id 的聯絡與區別

tolywang發表於2011-02-22

data_object_id究竟是個什麼東東,既然有了object_id那還要data_object_id幹嗎?
其實object_id和data_object_id同樣是表示資料庫物件的一個唯一標誌,但是object_id表示的是邏輯id,data_object_id表示的是物理

id。如果一些object沒有物理屬性的話那它就不存在data_object_id,例如procedure,function,package,data type,db link,mv定

義,view定義,臨時表,分割槽表定義等等這些object都是沒有對應著某個segment,因此它們的data_object_id都為空。
當表剛建立的時候它的object_id和data_object_id都是相等的,但是如果表經過move或truncate後那麼data_object_id將會有變化。

SQL 10G>select object_id,data_object_id from user_objects where object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
63053 63053

剛開始建立表時object_id=data_object_id。
SQL 10G>SELECT HEADER_FILE,HEADER_BLOCK,BLOCKS FROM DBA_SEGMENTS WHERE SEGMENT_NAME='T' AND WNER='TEST';
HEADER_FILE HEADER_BLOCK BLOCKS
----------- ------------ ----------
4 2019 8
SQL 10G>alter table t move;
Table altered.
SQL 10G>select object_id,data_object_id from user_objects where object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
63053 63463
在move以後可以看到data_object_id發生變化了。
SQL 10G>SELECT HEADER_FILE,HEADER_BLOCK,BLOCKS FROM DBA_SEGMENTS WHERE SEGMENT_NAME='T' AND WNER='TEST';
HEADER_FILE HEADER_BLOCK BLOCKS
----------- ------------ ----------
4 467 8
SQL 10G>truncate table t;
Table truncated.
SQL 10G>select object_id,data_object_id from user_objects where object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
63053 63464
SQL 10G>SELECT HEADER_FILE,HEADER_BLOCK,BLOCKS FROM DBA_SEGMENTS WHERE SEGMENT_NAME='T' AND WNER='TEST';
HEADER_FILE HEADER_BLOCK BLOCKS
----------- ------------ ----------
4 467 8
truncate之後雖然segment的位置沒有移動,但是data_object_id還是發生變化了。
SQL 10G>alter table t add(b number);
Table altered.
SQL 10G>select object_id,data_object_id from user_objects where object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
63053 63464
我們對t表加一個欄位,發現data_object_id沒有發生變化,我們可以認為只有當segment發生變化時data_object_id才會隨之變化。

我們來看看data_object_id從哪裡來的:
SQL 10G> select text from dba_views where view_name='DBA_OBJECTS';
select u.name, o.name, o.subname, o.obj#, o.dataobj#,
decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
13, 'TYPE', 14, 'TYPE BODY',
19, 'TABLE PARTITION', 20, 'INDEX PARTITION', 21, 'LOB',
22, 'LIBRARY', 23, 'DIRECTORY', 24, 'QUEUE',
28, 'JAVA SOURCE', 29, 'JAVA CLASS', 30, 'JAVA RESOURCE',
32, 'INDEXTYPE', 33, 'OPERATOR',
34, 'TABLE SUBPARTITION', 35, 'INDEX SUBPARTITION',
40, 'LOB PARTITION', 41, 'LOB SUBPARTITION',
42, NVL((SELECT distinct 'REWRITE EQUIVALENCE'
FROM sum$ s
WHERE s.obj#=o.obj#
and bitand(s.xpflags, 8388608) = 8388608),
'MATERIALIZED VIEW'),
43, 'DIMENSION',
44, 'CONTEXT', 46, 'RULE SET', 47, 'RESOURCE PLAN',
48, 'CONSUMER GROUP',
51, 'SUBSCRIPTION', 52, 'LOCATION',
55, 'XML SCHEMA', 56, 'JAVA DATA',
57, 'SECURITY PROFILE', 59, 'RULE',
60, 'CAPTURE', 61, 'APPLY',
62, 'EVALUATION CONTEXT',
66, 'JOB', 67, 'PROGRAM', 68, 'JOB CLASS', 69, 'WINDOW',
72, 'WINDOW GROUP', 74, 'SCHEDULE', 79, 'CHAIN',
81, 'FILE GROUP',
'UNDEFINED'),
o.ctime, o.mtime,
to_char(o.stime, 'YYYY-MM-DD:HH24:MI:SS'),
decode(o.status, 0, 'N/A', 1, 'VALID', 'INVALID'),
decode(bitand(o.flags, 2), 0, 'N', 2, 'Y', 'N'),
decode(bitand(o.flags, 4), 0, 'N', 4, 'Y', 'N'),
decode(bitand(o.flags, 16), 0, 'N', 16, 'Y', 'N')
from sys.obj$ o, sys.user$ u
where o.owner# = u.user#
and o.linkname is null
and (o.type# not in (1 /* INDEX - handled below */,
10 /* NON-EXISTENT */)
or
(o.type# = 1 and 1 = (select 1
from sys.ind$ i
where i.obj# = o.obj#
and i.type# in (1, 2, 3, 4, 6, 7, 9))))
and o.name != '_NEXT_OBJECT'
and o.name != '_default_auditing_options_'
union all
select u.name, l.name, NULL, to_number(null), to_number(null),
'DATABASE LINK',
l.ctime, to_date(null), NULL, 'VALID','N','N', 'N'
from sys.link$ l, sys.user$ u
where l.owner# = u.user#
可以看到data_object_id是從obj$.dataobj#來的,而obj$.dataobj#又對應著seg$.HWMINCR。
SQL 10G>select max(HWMINCR) from sys.seg$;
MAX(HWMINCR)
------------
63464
這裡的HWMINCR就是data_object_id的來源,每次seg$裡生成新的一條記錄都會增加HWMINCR這個值,同時obj$.dataobj#也會跟著變化。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-687676/,如需轉載,請註明出處,否則將追究法律責任。

相關文章