[20161021]显示记录顺序问题.txt

[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> commit ;
Commit complete.
--我间隔修改了数据记录。

SCOTT@book> select id,substr(pad,1,10) c10 from t;
ID C10
-- ----------
5 xxxxxxxxxx
7 xxxxxxxxxx
9 xxxxxxxxxx
1 xxxxxxxxxx
2
4
6
8
10
3 xxxxxxxxxx
10 rows selected.

--可以发现记录的显示顺序发生了变化。


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条记录出现了行迁移。

请使用浏览器的分享功能分享到微信等