行的迁移

create table t (x varchar2(20));

begin
  for i in 1..1000 loop
    insert into t values ('H');
  end loop;
  commit;
end;
/

收集对象的统计信息:
analyze table t compute statistics;

查看统计信息:
select TABLE_NAME,BLOCKS,EMPTY_BLOCKS,NUM_ROWS,AVG_ROW_LEN,CHAIN_CNT
from user_tables where table_name='T';

TABLE_NAME     BLOCKS EMPTY_BLOCKS   NUM_ROWS AVG_ROW_LEN  CHAIN_CNT
----------             ----------  ------------ ---------- ----------- ----------
T                        5            3                        1000              5                       0 --没有迁移

更新表产生迁移:
update t set x=rpad('H',20,'A');
commit;

重新收集对象的统计信息:
analyze table t compute statistics;

select TABLE_NAME,BLOCKS,EMPTY_BLOCKS,NUM_ROWS,AVG_ROW_LEN,CHAIN_CNT from user_tables where table_name='T';

TABLE_NAME     BLOCKS EMPTY_BLOCKS   NUM_ROWS AVG_ROW_LEN  CHAIN_CNT
---------- ---------- ------------ ---------- ----------- ----------
T                  13            3       1000          28        659--产生迁移

消除迁移:

1.exp --> drop --> imp
2.alter table t move; -->索引全失效-->alter index xxxx rebuild;
3.找到迁移的行导出,删除,导入
@?/rdbms/admin/utlchain      -->create table chained_rows ();

使用分析命令将产生迁移的行的rowid插入到chained_rows表:
analyze table t list chained rows into chained_rows;

导出发生迁移的行到临时表
create table tmp as select * from t where rowid in (select head_rowid from chained_rows);
删除迁移的行
delete t where rowid in (select head_rowid from chained_rows);
插入迁移的行
insert into t select * from tmp;
删除临时表
drop table tmp purge;

analyze table t compute statistics;

select TABLE_NAME,BLOCKS,EMPTY_BLOCKS,NUM_ROWS,AVG_ROW_LEN,CHAIN_CNT
from user_tables where table_name='T';
TABLE_NAME     BLOCKS EMPTY_BLOCKS   NUM_ROWS AVG_ROW_LEN  CHAIN_CNT
---------- ---------- ------------ ---------- ----------- ----------
T                  13            3       1000          28       0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值