首页 > Linux操作系统 > Linux操作系统 > 索引可以重用空间吗?
以下内容来自《oracle9i10g编程艺术》
create table t ( x int, constraint t_pk primary key(x));
insert into t values (1);
insert into t values (2);
insert into t values (9999999999);
naruto@ORCL>analyze index t_pk validate structure
2 /
索引已分析
naruto@ORCL>select lf_blks, br_blks, btree_space
2 from index_stats
3 /
LF_BLKS BR_BLKS BTREE_SPACE
---------- ---------- -----------
1 0 8000
只用了一个叶子块,0个分支,空间为8000byte
接下来不断的插入和删除,插入的值总比删除的值大1,如果索引不会重用空间,那么索引就会增长很大的空间。
naruto@ORCL>begin
2 for i in 2 .. 999999
3 loop
4 delete from t where x = i;
5 commit;
6 insert into t values (i+1);
7 commit;
8 end loop;
9 end;
10 /
PL/SQL 过程已成功完成。
naruto@ORCL>analyze index t_pk validate structure
2 /
索引已分析
naruto@ORCL> select lf_blks, br_blks, btree_space
2 from index_stats;
LF_BLKS BR_BLKS BTREE_SPACE
---------- ---------- -----------
1 0 8000
有结果可看出,每个值都没有变化,说明索引重用了被删除的index entry的空间。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25361369/viewspace-697522/ ,如需转载,请注明出处,否则将追究法律责任。