[20161021]顯示記錄順序問題.txt
--同僚在維護資料庫時,發現記錄顯示順序發生變化,看了一下操作過程,可以猜測可能維護後發生了行遷移導緻的情況。
--通過例子說明:
1.建立測試環境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------- ---------- ----------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SCOTT@book> create table t (id number,pad varchar2(4000));
Table created.
SCOTT@book> insert into t select rownum,null from dual connect by level<=10;
10 rows created.
SCOTT@book> commit ;
Commit complete.
SCOTT@book> select id,substr(pad,10) c10 from t;
ID C10
-- ----------
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SCOTT@book> update t set pad=lpad('x',4000,'x') where mod(id,2)=1;
5 rows updated.
--我間隔修改了資料記錄。
SCOTT@book> select id,substr(pad,1,10) c10 from t;
5 xxxxxxxxxx
7 xxxxxxxxxx
9 xxxxxxxxxx
1 xxxxxxxxxx
3 xxxxxxxxxx
--可以發現記錄的顯示順序發生了變化。
SCOTT@book> analyze table T list chained rows into chained_rows;
Table analyzed.
SCOTT@book> select id,substr(pad,1,10) c10 from t where rowid in (select HEAD_ROWID from chained_rows);
ID C10
---------- ----------
3 xxxxxxxxxx
5 xxxxxxxxxx
7 xxxxxxxxxx
9 xxxxxxxxxx
--有4條記錄出現了行遷移。