[20130312]undo与select for update.txt
闲着没事,研究一下undo与select for update.
DML操作在UNDO中的信息
通过Dump UNDO Block观察到DML操作记录在UNDO中的信息,主要为以下内容:
1、对于Insert操作,需要在UNDO中记录插入行的ROWID.
2、对于Update操作,需要在UNDO中记录被更新列的前镜像的值,同时也会记录被更新行的ROWID。
3、对于Delete操作,需要在UNDO中记录被删除行所有列的值(前镜像)及ROWID。
但是对于select for update的情况如何呢?
1、接着前面的测试继续测试select for update操作:
--先建立一个测试表,选择都是字符类型是为了显示方便.而且不建立使用,这样好分析一些.
SQL> select * from v$version where rownum
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
create table t (a varchar2(10),b varchar2(10));
insert into t values('1','a');
insert into t values('2','b');
insert into t values('3','c');
commit;
SQL> select t.rowid,t.* from t;
ROWID A B
------------------ ---------- ----------
AABCltAAEAAAAWdAAA 1 a
AABCltAAEAAAAWdAAB 2 b
AABCltAAEAAAAWdAAC 3 c
SQL> @lookup_rowid AABCltAAEAAAAWdAAA
OBJECT FILE BLOCK ROW
---------- ---------- ---------- ----------
272749 4 1437 0
2.执行select for update操作不提交:
SQL> select * from t where a =2 for update;
SQL> select dbms_transaction.local_transaction_id() x from dual ;
X
--------------------
18.13.154
SQL> select XIDUSN,XIDSLOT,XIDSQN,UBAFIL,UBABLK,UBAREC,STATUS from v$transaction;
XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK UBAREC STATUS
---------- ---------- ---------- ---------- ---------- ---------- ----------------
18 13 154 3 351 5 ACTIVE
--从以上操作发现,在select for update记录后UBAREC=5(0x05).
--从以上信息,可以知道在datafile 3 block 351.
--转储看看UBAREC=5的情况:(0x05)
alter system checkpoint ;
alter system dump datafile 3 block 20326;
********************************************************************************
UNDO BLK:
xid: 0x0012.00d.0000009a seq: 0xb5 cnt: 0x5 irb: 0x5 icl: 0x0 flg: 0x0000
Rec Offset Rec Offset Rec Offset Rec Offset Rec Offset
---------------------------------------------------------------------------
0x01 0x1f4c 0x02 0x1ec4 0x03 0x1e48 0x04 0x1de0 0x05 0x1d70
*-----------------------------
* Rec #0x5 slt: 0x0d objn: 272749(0x0004296d) objd: 272749 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: 0x00c0015f.00b5.02 ctl max scn: 0x0000.c0262e33 prv tx scn: 0x0000.c0262eb8
txn start scn: scn: 0x0000.c02638d7 logon user: 84
prev brb: 12583535 prev bcl: 0
KDO undo record:
KTB Redo
op: 0x03 ver: 0x01
compat bit: 4 (post-11) padding: 1
op: Z
KDO Op code: LKR row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x0100059d hdba: 0x0100059a
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 1 to: 0
--看看Rec=0x5,objn: 272749(0x0004296d) objd: 272749就是对应的对象.tblspc: 4(0x00000004)对应的就是文件编号.
--bdba: 0x0100059d ,里面就包含了块号. slot: 1(0x1)对应的就是行号1.
--hdba: 0x0100059a,表示该对象的块头.
--另外由于该事务包含1个记录.rci=0x00,表示事务开始.
SQL> @dfb 0100059d
RFILE# BLOCK#
---------- ----------
4 1437
SQL> @dfb 0100059a
RFILE# BLOCK#
---------- ----------
4 1434
SQL> select object_name, OBJECT_ID ,DATA_OBJECT_ID from dba_objects where object_name='T' and wner=user;
OBJECT_NAME OBJECT_ID DATA_OBJECT_ID
-------------------- ---------- --------------
T 272749 272749
SQL> select header_file,header_block from dba_segments where wner=user and segment_name='T';
HEADER_FILE HEADER_BLOCK
----------- ------------
4 1434
--可以发现undo的信息基本上与insert一样,需要在UNDO中记录插入行的ROWID.
时间: 2024-09-20 12:23:56