0x06 0x1d90 0x07 0x1d20
*-----------------------------
* Rec #0x7 slt: 0x15 objn: 73430(0x00011ed6) objd: 73430 tblspc: 4(0x00000004)
* Layer: 11 (Row) opc: 1 rci 0x00
Undo type: Regular undo Begin trans Last buffer split: No
Temp Object: No
Tablespace Undo: No
rdba: 0x00000000Ext idx: 0
flg2: 0
*-----------------------------
uba: 0x00c005b9.012c.2d ctl max scn: 0x0000.000f4ed4 prv tx scn: 0x0000.000f4ee0
txn start scn: scn: 0x0000.000f53a9 logon user: 85
prev brb: 12584373 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post-11) padding: 1
op: Z
KDO Op code: DRP row dependencies Disabled --DRP操作完成回滚
xtype: XA flags: 0x00000000 bdba: 0x0100047e hdba: 0x0100032a --bdba表示block address hdba 代表sgment header address
itli: 1 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0) ---------这个slot表示这一行数据在数据块中的行地址(行序列)
其中bdba表示file 4,block 1150 ,hdba表示file 4,block 810 与我们上面查询出来的地址相符。
我们可以看到,undo块中并没有直接保存rowid信息,但是oracle完全可以根据上面的几个信息(bdba,slot,objd)定位回滚时需要删除的具体数据,因此对于Insert操作,ORACLE只需保留上述信息,即可完成回滚操作
三、基本概念和名词解释
UBA: Undo block address
RBA: Redo block address
Dba: Data block address
Rdba: Root dba
Xid: Transaction ID
ITL: Interested Transaction List 保存在数据块的头部(事务信息部分),包含XID,UBA,LCK,FLG等重要信息
Transaction Identifiers
Transaction identifiers (XID) uniquely identify a transaction within the system; they are used within the Interested Transaction List (ITL) of the data block.
A transaction identifier consists of:
Undo segment number 即v$rollname中的usn
Transaction table slot number 对应回滚段头中回滚事务表的第几条记录
Sequence number or wrap#
XID = usn# . slot# . wrap#
Undo Block Address
The undo block address (UBA) uniquely identifies the undo block for a given transaction; it is found within the ITL of the data block.
A UBA consists of:
Data block address (DBA) of the block 前映像undo 块地址
The sequence number of the block 序列号
The record number within the block undo记录的开始地址(针对该块)
UBA = DBA. seq#. rec#
四、从一个DML语句开始研究,SESSION A执行下面的语句,更新完成后先不提交
(1)session A执行更新,更新两条数据,如下
SQL> select * from undotest where object_type='PROCEDURE' and id in (4703,4704);
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------------
4703 4771 SUBPTXT2 PROCEDURE
4704 4772 SUBPTXT PROCEDURE
SQL> update undotest set object_type='VIEW' where object_type='PROCEDURE' and id in (4703,4704);
2 rows updated.
SQL> select * from undotest where id in (4703,4704);
ID OBJECT_ID OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------------
4703 4771 SUBPTXT2 VIEW
4704 4772 SUBPTXT VIEW
(2)查询更新数据块的信息和事务信息
sQL> SELECT
2 dbms_rowid.rowid_object(rowid) object_id,
3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
4 dbms_rowid.rowid_block_number(rowid) BLOCKNO,
5 dbms_rowid.rowid_row_number(rowid) ROWNO,rowid,id,object_name,object_type
6 FROM dh.undotest WHERE id in (4703,4704);
OBJECT_ID REL_FNO BLOCKNO ROWNO ROWID ID OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------- ---------- ------------------ ---------- -------------------- ---------------
73424 4 195 70 AAAR7QAAEAA