行链接是指一个行的大小超过了一个块的可用大小,导致一个行存储在多个块中的情况
行迁移是指一个行因为不断的被更新变大,导致原有的块存放不下该行,而将该行的数据整行迁移到另外 一个合适的块中,而原块中留下一个指针指向迁移后的块,行迁移后rowid不变。行迁移特别容易出现在表增加字段后。
查找行链接和行迁移
1、运行脚本@$ORACLE_HOME/rdbms/admin/utlchain.sql
该脚本其实只做一件事,创建chained_rows表:
create table CHAINED_ROWS (
owner_name varchar2(30),
table_name varchar2(30),
cluster_name varchar2(30),
partition_name varchar2(30),
subpartition_name varchar2(30),
head_rowid rowid,
analyze_timestamp date
);
2、analyze table test list chained rows;
3、select * from chained_rows;
解决方法:
[@more@]1、(1)创建临时表create table test_hist as select * from test
where rowid in (select head_rowid from chained_rows where table_name='TEST');
(2)删除产生行迁移的行
delete from test where rowid in (select head_rowid from chained_rows where table_name='TEST');
(3)将产生行迁移的行重新插入表中
insert into test select * from test_hist;
(4)删除临时表和统计表中数据
drop table test_hist
delete from chained_rows where table_name='TEST';
2、move表
alter table test move;
此命令会使行的rowid改变,导致索引失效,需要重建索引,并且需要重新收集统计信息。
下面为实验:
首先我创建了一张300W数据量pctfree为0的大表:
SQL> select count(*) from big;
COUNT(*)
----------
3220736
SQL> select pct_free from dba_tables where table_name='BIG';
PCT_FREE
----------
0
SQL> analyze table big list chained rows;
表已分析。
SQL> select count(*) from chained_rows;
COUNT(*)
----------
0
SQL> alter table big add test_id number;
表已更改。
SQL> update big set test_id=1 where rownum <=1000000;
已更新1000000行。
SQL> commit;
提交完成。
SQL> analyze table big list chained rows;
表已分析。
SQL> select count(*) from chained_rows;
COUNT(*)
----------
31919
SQL> create table big_hist as select * from big
2 where rowid in (select head_rowid from chained_rows where table_name='BIG');
表已创建。
SQL> delete from big where rowid in (select head_rowid from chained_rows where table_name='BIG');
已删除31919行。
SQL> insert into big select * from big_hist;
已创建31919行。
SQL> commit;
提交完成。
SQL> drop table big_hist purge;
表已删除。
SQL> delete from chained_rows where table_name='BIG';
已删除31919行。
SQL> commit;
提交完成。
SQL> analyze table big list chained rows;
表已分析。
SQL> select count(*) from chained_rows;
COUNT(*)
----------
0
SQL> analyze table big list chained rows;
表已分析。
已用时间: 00: 00: 07.40
实验最后分析了解了analyze list chained rows语句的大概时间,300W的数据在6-7秒左右
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10176825/viewspace-1028893/ ,如需转载,请注明出处,否则将追究法律责任。