SQL> update tn set b = lpad('sd',999); 10 rows updated. SQL> commit; Commit complete. SQL> alter system dump datafile 3 block 1955; System altered. SQL> update tn set b ='QQqqqqq'; 10 rows updated. SQL> commit; Commit complete. SQL> alter system dump datafile 3 block 1955; System altered. 首先更新到讓記錄發生了行遷移,然后再更新回來,因為這時數據太大,就不把發生遷移后的數據全部貼出來,給個再更新回來的結果 Block header dump: 0x00c007a3 Object id on Block? Y seg/obj: 0x66b7 csc: 0x00.1891ba5 itc: 1 flg: O typ: 1 - DATA fsl: 1 fnx: 0x0 ver: 0x01 Itl Xid Uba Flag Lck Scn/Fsc0x01 xid: 0x0004.047.000000e7 uba: 0x00800618.00df.08 --U- 11 fsc 0x1b2e.01891ba7 data_block_dump===============tsiz: 0x1fb8hsiz: 0x28pbl: 0x0ba76c44bdba: 0x00c007a3flag=-----------ntab=1nrow=11frre=7fsbo=0x28fSEO=0x2f6avsp=0x3d0tosp=0x1efe0xe:pti[0] nrow=11 offs=00x12:PRi[0] offs=0x35c -------位置都發生了變化0x14:pri[1] offs=0x34b0x16:pri[2] offs=0x33a0x18:pri[3] offs=0x3290x1a:pri[4] offs=0x3180x1c:pri[5] offs=0x3070x1e:pri[6] offs=0x2f60x20:pri[7] sfll=-10x22:pri[8] offs=0x7f00x24:pri[9] offs=0x7da0x26:pri[10] offs=0x760block_row_dump:tab 0, row 0, @0x35ctl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 1, @0x34btl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 03col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 2, @0x33atl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 04col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 3, @0x329tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 05col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 4, @0x318tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 06col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 5, @0x307tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 07col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 6, @0x2f6tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 14col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 8, @0x7f0 -------------- 從row 8 --- row 10 的記錄已經遷移到新的block中,這里保留的是新塊的物理位置tl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.0 ------------ 遷移到了 block編號為 0x00c007a4 的塊中的 row 0 (本塊為 0x00c007a3)tab 0, row 9, @0x7datl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.1 遷移到了 block編號為 0x00c007a4 的塊中的 row 1 (本塊為 0x00c007a3)tab 0, row 10, @0x760tl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.2 遷移到了 block編號為 0x00c007a4 的塊中的 row 2 (本塊為 0x00c007a3)end_of_block_dumpEnd dump data blocks tsn: 2 file#: 3 minblk 1955 maxblk 1955 SQL> insert into tn values(1,1,1); 1 row created. SQL> commit; Commit complete. SQL> alter system dump datafile 3 block 1955; System altered. 再插入記錄,我們看看位置,我們發現該塊并沒有被插入記錄,記錄是插入到了 另外一個塊(雖然該塊現在空間使用率并不高) 這是因為在update的時候先脫離了freelist然后又回到freelist了,排在了 block 1956 之后 Block header dump: 0x00c007a3 Object id on Block? Y seg/obj: 0x66b7 csc: 0x00.1891ba5 itc: 1 flg: O typ: 1 - DATA fsl: 1 fnx: 0x0 ver: 0x01 Itl Xid Uba Flag Lck Scn/Fsc0x01 xid: 0x0004.047.000000e7 uba: 0x00800618.00df.08 --U- 11 fsc 0x1b2e.01891ba7 data_block_dump===============tsiz: 0x1fb8hsiz: 0x28pbl: 0x0ba76c44bdba: 0x00c007a3flag=-----------ntab=1nrow=11frre=7fsbo=0x28fseo=0x2f6avsp=0x3d0tosp=0x1efe0xe:pti[0] nrow=11 offs=00x12:pri[0] offs=0x35c0x14:pri[1] offs=0x34b0x16:pri[2] offs=0x33a0x18:pri[3] offs=0x3290x1a:pri[4] offs=0x3180x1c:pri[5] offs=0x3070x1e:pri[6] offs=0x2f60x20:pri[7] sfll=-10x22:pri[8] offs=0x7f00x24:pri[9] offs=0x7da0x26:pri[10] offs=0x760block_row_dump:tab 0, row 0, @0x35ctl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 1, @0x34btl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 03col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 2, @0x33atl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 04col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 3, @0x329tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 05col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 4, @0x318tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 06col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 5, @0x307tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 07col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 6, @0x2f6tl: 17 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 14col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 8, @0x7f0tl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.0tab 0, row 9, @0x7datl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.1tab 0, row 10, @0x760tl: 9 fb: --H----- lb: 0x1 cc: 0nrid: 0x00c007a4.2end_of_block_dumpEnd dump data blocks tsn: 2 file#: 3 minblk 1955 maxblk 1955 SQL> insert into tn select 1,1,1 from all_objects where rownum < 1001; 1000 rows created. SQL> commit; Commit complete. SQL> alter system dump datafile 3 block 1955; System altered. SQL> 再插入1000條記錄,我們發現其中600條插到了 block 1956中,而本塊只插入了400條,這是因為freelist中的順序問題 并且我們發現,本塊中原來存在的記錄已經完全重新組織過,物理位置都因為insert而發生了變化 也就是說Oracle 的 block中的記錄物理位置是可能重組的,但不變的是 行號,這個行號和物理位置記錄在 前部,供通過 rowid 查詢的時候快速定位 Block header dump: 0x00c007a3 Object id on Block? Y seg/obj: 0x66b7 csc: 0x00.1891bab itc: 1 flg: O typ: 1 - DATA fsl: 0 fnx: 0x0 ver: 0x01 Itl Xid Uba Flag Lck Scn/Fsc0x01 xid: 0x0006.01e.000000f2 uba: 0x00801660.00da.14 --U- 400 fsc 0x0000.01891bad data_block_dump===============tsiz: 0x1fb8hsiz: 0x346pbl: 0x0ba76c44bdba: 0x00c007a3flag=-----------ntab=1nrow=410frre=-1fsbo=0x346fseo=0xf86avsp=0xc40tosp=0xc400xe:pti[0] nrow=410 offs=00x12:pri[0] offs=0x1fa7 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x14:pri[1] offs=0x1f96 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x16:pri[2] offs=0x1f85 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x18:pri[3] offs=0x1f74 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x1a:pri[4] offs=0x1f63 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x1c:pri[5] offs=0x1f52 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x1e:pri[6] offs=0x1f41 先前的7條記錄物理位置已經發生變化但是行號沒有改變0x20:pri[7] offs=0x18b4 該行號已經被新的記錄插入0x22:pri[8] offs=0x1f38 該行遷移發生的記錄沒有發生變化,這是因為這樣不用更新索引0x24:pri[9] offs=0x1f2f 該行遷移發生的記錄沒有發生變化,這是因為這樣不用更新索引0x26:pri[10] offs=0x1f26 該行遷移發生的記錄沒有發生變化,這是因為這樣不用更新索引0x28:pri[11] offs=0x18be 新插入的記錄0x2a:pri[12] offs=0x18c8 新插入的記錄0x2c:pri[13] offs=0x18d2 新插入的記錄0x2e:pri[14] offs=0x18dc 新插入的記錄0x30:pri[15] offs=0x18e6 新插入的記錄0x32:pri[16] offs=0x18f0 新插入的記錄0x34:pri[17] offs=0x18fa 新插入的記錄0x36:pri[18] offs=0x1904 新插入的記錄…………………………………………………… 省略掉一些block_row_dump:tab 0, row 0, @0x1fa7tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 02col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 1, @0x1f96tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 03col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 2, @0x1f85tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 04col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 3, @0x1f74tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 05col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 4, @0x1f63tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 06col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 5, @0x1f52tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 07col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 6, @0x1f41tl: 17 fb: --H-FL-- lb: 0x0 cc: 3col 0: [ 2] c1 14col 1: [ 7] 71 71 71 71 71 71 71col 2: [ 2] 70 70tab 0, row 7, @0x18b4tl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 8, @0x1f38tl: 9 fb: --H----- lb: 0x0 cc: 0nrid: 0x00c007a4.0tab 0, row 9, @0x1f2ftl: 9 fb: --H----- lb: 0x0 cc: 0nrid: 0x00c007a4.1tab 0, row 10, @0x1f26tl: 9 fb: --H----- lb: 0x0 cc: 0nrid: 0x00c007a4.2tab 0, row 11, @0x18betl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 12, @0x18c8tl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 13, @0x18d2tl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 14, @0x18dctl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 15, @0x18e6tl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31col 2: [ 1] 31tab 0, row 16, @0x18f0tl: 10 fb: --H-FL-- lb: 0x1 cc: 3col 0: [ 2] c1 02col 1: [ 1] 31 省略掉后面重復的數據 結論 1: 當block中開始插入數據的時候,正常插入 2:當刪除記錄后的空間,假如新插入的數據能容納進去,則重用 3: 當更新的時候,假如 row 長度沒有增加,則位置不變,假如長度增加,則被遷移到整個塊的最前記錄之前(靠近 block header 一側) 4:當發生行遷移的時候,在原物理位置保留 遷移后的 block位置和 row number 5:當block重新返回freelist 再插入記錄的時候,可能發生block數據的重組(row number不變但是物理位置發生變化),到底什么時候重組,有待進一步考證