data_object_id 及 object_id 的聯絡與區別
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- JRE與JDK的區別與聯絡JDK
- cookie與session的區別與聯絡CookieSession
- Session與Cookie的區別與聯絡SessionCookie
- Kafka與ActiveMQ的區別與聯絡詳解KafkaMQ
- 詳解Kafka與ActiveMQ的區別與聯絡!KafkaMQ
- B/S與C/S的聯絡與區別
- javaSE中的==和equals的聯絡與區別Java
- Python: 列表、陣列及迭代器切片的區別及聯絡Python陣列
- 程式和執行緒的區別與聯絡執行緒
- HDFS 塊和 Input Splits 的區別與聯絡
- 感知器、logistic與svm 區別與聯絡
- ipv4與ipv6的聯絡與區別
- jQuery與JavaScript與ajax三者的區別與聯絡jQueryJavaScript
- 簡述Spring容器與SpringMVC的容器的聯絡與區別SpringMVC
- KPI vs OKR:區別與聯絡的終極指南KPIOKR
- Vue中watch、computed與methods的聯絡和區別Vue
- 單機、分散式、叢集的區別與聯絡分散式
- SCADA和PLC的區別聯絡
- 陣列地址與指標之間的區別與聯絡陣列指標
- 淺析HTML、CSS、JavaScript之間的聯絡與區別!HTMLCSSJavaScript
- Python中__new__和__init__的區別與聯絡Python
- 叢集、負載均衡、分散式的區別與聯絡負載分散式
- Instruction和Question的區別和聯絡Struct
- http、socket、tcp的區別和聯絡?HTTPTCP
- Unicode,UTF-8和UTF-16的區別與聯絡Unicode
- ARM晶片、核心、架構、指令集的聯絡與區別晶片架構
- 一文搞懂灰度釋出與 AB Test 的聯絡與區別
- tcp/ip和http的區別和聯絡TCPHTTP
- `std::packaged_task`、`std::thread` 和 `std::async` 的區別與聯絡Packagethread
- 可觀測性與傳統監控的區別和聯絡
- 【Python入門必看】Python中Cookie和Session的區別與聯絡!PythonCookieSession
- 跟你深入剖析可迭代物件和迭代器的區別與聯絡物件
- 先驗概率與後驗概率、貝葉斯區別與聯絡
- 大資料分析與機器學習之間的區別與聯絡大資料機器學習
- annotation之context:annotation-config與 context:component-scan的區別與聯絡Context
- Rxjs map, mergeMap 和 switchMap 的區別和聯絡JS
- 產品經理和專案經理區別與聯絡
- Linux中程式和執行緒的區別與聯絡,建議收藏!Linux執行緒
- 【科普】等級保護與分級保護的區別和聯絡!