关于oracle的行迁移

来源:互联网 发布:淘宝店网页制作 编辑:程序博客网 时间:2024/05/17 08:32

行衔接和行迁移:

行衔接一般是由于不合理的表结构设计所致,导致一个块中容不下一个行,需要多个块来存储一个行。

行迁移是由于原本存储给行的空间无法存储update操作需要的行空间,只能将行的数据存储到其他块上,原来的行信息就可以视为是转发地址。行迁移导致读取一行信息可能需要扫描两个块。每一行都会为行的扩展保留一定空间(默认为%10)。修改保留空间大小:alter table <table_name> pctfree 50;

实例:

1.create table wm235 (c1 varchar2(20));
2.
begin
for i in 1..1000 loop
insert into wm235 values(‘abcd’);
end loop;
end;
3.分析并统计表信息
analyze table wm235 compute statistics;
查看表的平均长度以及发生行迁移想象的数目
select avg_row_len,chain_cnt from user_tables where table_name='WM235';

对于平均行长度一值,附上一段英文解释:

A row fully contained in one block has at least 3 bytes of row header. After the row header information, each row contains column length and data. The column length requires 1 byte for columns that store 250 bytes or less, or 3 bytes for columns that store more than 250 bytes, and precedes the column data. Space required for column data depends on the datatype. If the datatype of a column is variable length, then the space required to hold a value can grow and shrink with updates to the data.

4. 数据更新,列增长,可能发生行迁移

update wm235 set c1='1234567890';

5.

analyze table wm235 compute statistics;
select avg_row_len,chain_cnt from user_tables where table_name='WM235';

6. 消除行迁移现象

alter table wm235 move;

(move 实际是再底层调用了create tables as select as操作,因此所有行的ROWID都会发生变更,也就是说该表的所有索引都会失效)

7. 重建索引
alter index index_name rebuild tablespace tablespace_name 
alter index index_name rebuild tablespace tablespace_name 加入表空间名,会将指定的索引移动到指定的表空间当中。

0 0
原创粉丝点击