離線重建:
方法: 建立一個新區段再將索引指向新的區段並刪除舊的索引區段
create table test1 as select * from dba_objects;
create index index_1 on test1(object_id);
execute dbms_stats.gather_table_stats('SYS','TEST1');
analyze index index_1 validate structure;
select name,blocks,lf_blks,(del_lf_rows_len/lf_rows_len)*100
from index_stats;
#目前樹葉區塊空間浪費是0
delete test1 where mod(object_id,3)=0; / 接著測試刪除一些資料
已刪除. 16,929 個資料列
analyze index index_1 validate structure; /再分析
select name,blocks,lf_blks,(del_lf_rows_len/lf_rows_len)*100
from index_stats;
#空間浪費33.3%
執行索引重建 SQL>alter index index_1 rebuild;
#空間浪費恢復成0%了,樹葉區塊(122->75)與總資料區塊(120->80)都減少了,因為索引區段為新的區段,因此每個樹葉區塊都塞滿了索引項目
文章標籤
全站熱搜
