oracle在對錶進行多事務插入時,採用的是分佈式多數據塊插入,oracle表初始事務槽數量是ini_trans爲2,最多兩個事務對同一個數據塊進行插入,而其餘的事務則插入到新塊中,這樣就不會產生事務槽的爭用。
- 會話一
- SQL> insert into scott.t1 values (1);
- insert into scott.t1 values (2);
- insert into scott.t1 values (3);
- insert into scott.t1 values (4);
- insert into scott.t1 values (5);
- SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1;
- ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ---------- ------------------------------------ ------------------------------------
- 1 4 171
- 2 4 171
- 3 4 171
- 4 4 171
- 5 4 171
- 會話2
- SQL> insert into scott.t1 values (5);
- insert into scott.t1 values (6);
- insert into scott.t1 values (7);
- SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1;
- ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ---------- ------------------------------------ ------------------------------------
- 5 4 173
- 6 4 173
- 7 4 173
- 會話3
- SQL> insert into scott.t1 values (8);
- SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1;
- ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ---------- ------------------------------------ ------------------------------------
- 8 4 172
- SQL> alter system dump datafile 4 block min 171 block max 173;
- SQL> ho vim /opt/app/oracle/diag/rdbms/db2/db2/trace/db2_ora_18916.trc
- buffer tsn: 4 rdba: 0x010000ab (4/171)
- seg/obj: 0x12160 csc: 0x00.5a3ec5 itc: 2 flg: E typ: 1 - DATA
- brn: 0 bdba: 0x10000a8 ver: 0x01 opc: 0
- inc: 0 exflg: 0
- Itl Xid Uba Flag Lck Scn/Fsc
- 0x01 0x0009.01c.0000031c 0x00c0024c.00d0.10 ---- 5 fsc 0x0000.00000000
- 0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
- block_row_dump:
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 02
- tab 0, row 1, @0x1f8c
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 03
- tab 0, row 2, @0x1f86
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 04
- tab 0, row 3, @0x1f80
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 05
- tab 0, row 4, @0x1f7a
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 06
- buffer tsn: 4 rdba: 0x010000ac (4/172)
- seg/obj: 0x12160 csc: 0x00.5a3e7e itc: 2 flg: E typ: 1 - DATA
- brn: 0 bdba: 0x10000a8 ver: 0x01 opc: 0
- inc: 0 exflg: 0
- Itl Xid Uba Flag Lck Scn/Fsc
- 0x01 0x0005.021.00000362 0x00c002e4.010b.01 ---- 1 fsc 0x0000.00000000
- 0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
- block_row_dump:
- tab 0, row 0, @0x1f92
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 09
- buffer tsn: 4 rdba: 0x010000ad (4/173)
- seg/obj: 0x12160 csc: 0x00.5a3e7e itc: 2 flg: E typ: 1 - DATA
- brn: 0 bdba: 0x10000a8 ver: 0x01 opc: 0
- inc: 0 exflg: 0
- Itl Xid Uba Flag Lck Scn/Fsc
- 0x01 0x000c.016.00000017 0x00c007e6.001f.05 ---- 3 fsc 0x0000.00000000
- 0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
- block_row_dump:
- tab 0, row 0, @0x1f92
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 06
- tab 0, row 1, @0x1f8c
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 07
- tab 0, row 2, @0x1f86
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 08
- 可以看出多事務插入時,採用了多個塊插入,每個數據塊都產生了兩個事務槽,使用了其中一個,每個事務槽的修改對應了所修改的行。
update時當同時修改一個數據塊中的行時,每個回話都會在塊中有一個對應的事務槽,max_trans默認是255,發生ITL的爭用比較少;
- SQL> declare
- 2 begin
- 3 for i in 1..10 loop
- 4 insert into scott.t1 values (i);
- 5 end loop;
- 6 commit;
- 7 end;
- 8 /
- SQL> select id,dbms_rowid.rowid_relative_fno(rowid),dbms_rowid.rowid_block_number(rowid) from scott.t1;
- ID DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ---------- ------------------------------------ ------------------------------------
- 1 4 171
- 2 4 171
- 3 4 171
- 4 4 171
- 5 4 171
- 6 4 171
- 7 4 171
- 8 4 171
- 9 4 171
- 10 4 171
- 會話1
- SQL> update scott.t1 set idid =id where id in (1,2,3,4);
- 4 rows updated.
- 會話2
- SQL> update scott.t1 set idid =id where id in (5,6,7,8);
- 4 rows updated.
- 會話3
- SQL> update scott.t1 set idid =id where id in (9,10);
- 2 rows updated.
- SQL> alter system dump datafile 4 block 171;
- SQL> ho vim /opt/app/oracle/diag/rdbms/db2/db2/trace/db2_ora_18916.trc
- Start dump data blocks tsn: 4 file#:4 minblk 171 maxblk 171
- Object id on Block? Y
- seg/obj: 0x12162 csc: 0x00.5a44d4 itc: 3 flg: E typ: 1 - DATA
- brn: 0 bdba: 0x10000a8 ver: 0x01 opc: 0
- inc: 0 exflg: 0
- Itl Xid Uba Flag Lck Scn/Fsc
- 0x01 0x000a.00c.0000028d 0x00c000bd.00dd.07 ---- 4 fsc 0x0000.00000000
- 0x02 0x0008.007.000003f8 0x00c0037a.00c5.06 ---- 4 fsc 0x0000.00000000
- 0x03 0x0003.006.0000033c 0x00c00c9b.0175.01 ---- 2 fsc 0x0000.00000000
- block_row_dump:
- tab 0, row 0, @0x1f7a
- tl: 6 fb: --H-FL-- lb: 0x2 cc: 1
- col 0: [ 2] c1 02
- tab 0, row 1, @0x1f74
- tl: 6 fb: --H-FL-- lb: 0x2 cc: 1
- col 0: [ 2] c1 03
- tab 0, row 2, @0x1f6e
- tl: 6 fb: --H-FL-- lb: 0x2 cc: 1
- col 0: [ 2] c1 04
- tab 0, row 3, @0x1f68
- tl: 6 fb: --H-FL-- lb: 0x2 cc: 1
- col 0: [ 2] c1 05
- tab 0, row 4, @0x1f62
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 06
- tab 0, row 5, @0x1f5c
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 07
- tab 0, row 6, @0x1f56
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 08
- tab 0, row 7, @0x1f50
- tl: 6 fb: --H-FL-- lb: 0x1 cc: 1
- col 0: [ 2] c1 09
- tab 0, row 8, @0x1f4a
- tl: 6 fb: --H-FL-- lb: 0x3 cc: 1
- col 0: [ 2] c1 0a
- tab 0, row 9, @0x1f44
- tl: 6 fb: --H-FL-- lb: 0x3 cc: 1
- col 0: [ 2] c1 0b
- 可以看到,每個UPDATE的會話都有一個事務槽對應,前兩個會話的事務槽每個對應4行,第三個對應2行
事務槽(事務,是否提交,鎖定)
事務正在使用的回滾段,轉向 http://rilee.blog.51cto.com/467020/772463