索引碎片的分析和整理
索引碎片产生的原因:对索引字段频繁地进行delete、update操作,会对索引造成大量的碎片。
影响:极大地影响了索引的使用效率,并造成索引i/0的增加。
1、索引碎片分析
分析语句:
SQL>analyze index <index_name> validate structure online;
分析表:
analyze table tablename compute statistics;
analyze index indexname compute statistics;
查看索引碎片的情况:
SQL>select name,del_lf_rows_len,lf_rows_len,(del_lf_rows_len/lf_rows_len)*100 from index_stats;
索引碎片率:(del_lf_rows_len/lf_rows_len)*100
如果索引碎片率超过20%,oracle就会认为索引碎片已经非常严重,此时就需要对索引碎片进行整理。
2、索引碎片整理
索引碎片整理包括两种策略:
(1)重建索引(rebuild)
SQL>alter index <index_name> rebuild;
(2)压缩索引(coalesce)
SQL>alter index <index_name> coalesce;
oracle建议定期分析之后采用重建索引(rebuild)的策略。