行的链接与行的迁移

行的链接:是表结构设计问题(表太宽)!不可消除!将表垂直分割!

行的迁移:insert

char(20) –>

drop table t purge;
create table t (x varchar2(20));

begin
for i in 1..1000 loop
insert into t values (‘A’);
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=’AAAAAAAAAAAAAAAAAAAA’;
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’;

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注