由USED=NO可知,idx_t_created索引没有被使用。
- SQL> alter index idx_t_created monitoring usage;
- Index altered
- SQL> select * from t where t.created=sysdate;
- SQL> alter index idx_t_created nomonitoring usage;
- Index altered
- SQL> select * from v$object_usage;
- INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
- ------------------------------ ------------------------------ ---------- ---- ------------------- -------------------
- IDX_T_CREATED T NO YES 06/27/2011 21:33:38 06/27/2011 21:34:20
以上可以看出idx_t_created索引已经被使用了。
索引碎片分析与整理
建议每周监测一次索引的碎片情况,根据情况制定索引的重建频率以提高索引使用效率。
SQL> analyze index <index_name> structure;
SQL> select name,del_lf_rows_len,lf_rows_len,(del_lf_rows_len/lf_rows_len)*100 from index_stats;
索引碎片率(%) = (被删除的索引长度/索引总长)*100
SQL> alter index <索引名> rebuild;
SQL> alter index <索引名> coalesce;
1.如果索引的叶子行的碎片超过20%,考虑对索引进行重建。
alter index 用户名.索引名 rebuild tablespace 表空间名 storage(initial 初始值 next 扩展值) nologging
重建索引时要注意以下几点:
a.如果不指定tablespace名,索引将建在用户的默认表空间。
b.如果不指定nologging,将会写日志,导致速度变慢。由于索引的重建没有恢复的必要,所以,可以不写日志。
c.如果出现资源忙,表明有进程正在使用该索引,等待一会再提交。
2.如果出于空间或其他考虑,不能重建索引,可以整理索引。
alter index用户名.索引名 coalesce
我查询index_stats总是没有记录,不知为何?
