her_table_stats(user, 'T');
PL/SQL procedure successfully completed.
tony@ORA11GR2> select table_name, blocks, empty_blocks from user_tables where table_name = 'T';
TABLE_NAME BLOCKS EMPTY_BLOCKS
---------------------------------------- ---------- ------------
T 86 0
tony@ORA11GR2> select segment_name, extents, blocks, initial_extent from user_segments where segment_name = 'T';
SEGMENT_NAME EXTENTS BLOCKS INITIAL_EXTENT
---------------------------------------- ---------- ---------- --------------
T 5 640 5242880
tony@ORA11GR2> select count(distinct dbms_rowid.rowid_block_number(rowid)) from t;
COUNT(DISTINCTDBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID))
---------------------------------------------------
82
tony@ORA11GR2> alter table t enable row movement;
Table altered.
tony@ORA11GR2> alter table t shrink space;
Table altered.
tony@ORA11GR2> select index_name, status from user_indexes where table_name = 'T';
INDEX_NAME STATUS
---------------------------------------- ----------------
T_IDX VALID
tony@ORA11GR2> exec dbms_stats.gather_table_stats(user, 'T');
PL/SQL procedure successfully completed.
tony@ORA11GR2> select table_name, blocks, empty_blocks from user_tables where table_name = 'T';
TABLE_NAME BLOCKS EMPTY_BLOCKS
---------------------------------------- ---------- ------------
T 86 0
tony@ORA11GR2> select segment_name, extents, blocks, initial_extent from user_segments where segment_name = 'T';
SEGMENT_NAME EXTENTS BLOCKS INITIAL_EXTENT
---------------------------------------- ---------- ---------- --------------
T 1 88 5242880
tony@ORA11GR2> select count(distinct dbms_rowid.rowid_block_number(rowid)) from t;
COUNT(DISTINCTDBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID))
---------------------------------------------------
82
下面这www.2cto.com个例子可以验证alter table t move和alter table t shrink space都可以用来消除行链接(Row Chaining)和行迁移(Row Migration)。
为此需要先建立chained_rows表格。
首先执行$ORACLE_HOME/RDBMS/ADMIN/utlchain.sql脚本建立chained_rows表格,
然后执行analyze table xxx list chained rows [into chained_rows],
如果存在行链接或者行迁移,查询chained_rows就能找到发生了行链接或者行迁移的行。
tony@ORA11GR2> drop table t purge;
Table dropped.
tony@ORA11GR2> create table t
2 ( x int primary key,
3 y varchar2(4000)
4 );
Table created.
tony@ORA11GR2> insert into t (x,y)
2 select rownum, rpad('*',148,'*')
3 from dual
4 connect by level <= 46;
46 rows created.
tony@ORA11GR2> update t set y = rpad('*',2000,'*') where x = 1;
1 row updated.
tony@ORA11GR2> analyze table t list chained rows;
Table analyzed.
tony@ORA11GR2> select count(*) from chained_rows;
COUNT(*)
|