对于索引的调整,我们可以通过oracle提供的索引监控特性来跟踪索引是否被使用。尽管该特性并未提供索引使用的频度,但仍不失为我
对于索引的调整,我们可以通过oracle提供的索引监控特性来跟踪索引是否被使用。尽管该特性并未提供索引使用的频度,但仍不失为我们参考的方式之一。然而,最近在oracle 10.2.0.3中发现收集统计信息时导致索引也被监控,而不是用于sql查询引发的索引监控。如此这般,,索引监控岂不是鸡肋?
1、基于oracle 10g 收集统计信息索引被监控情形
scott@cnmmbo> select * from v$version where rownum
banner
----------------------------------------------------------------
oracle database 10g release 10.2.0.3.0 - 64bit production
--创建临时表t
scott@cnmmbo> create table t(id number constraint t_pk primary key);
table created.
--启用索引监控
scott@cnmmbo> alter index t_pk monitoring usage;
index altered.
--查看对象的使用情况
scott@cnmmbo> select * from v$object_usage where index_name='t_pk';
index_name table name mon use start_monitoring end_monitoring
------------------------------ ----------------- --- --- ------------------- -------------------
t_pk t yes no 03/22/2013 20:53:23
--收集表t上的统计信息
scott@cnmmbo> exec dbms_stats.gather_table_stats('scott','t',cascade=>true);
pl/sql procedure successfully completed.
--下面的查询中提示索引没有被使用
--这应该是由于表上没有数据的缘故,也就不存在对应的索引段
scott@cnmmbo> select * from v$object_usage where index_name='t_pk';
index_name table name mon use start_monitoring end_monitoring
------------------------------ ----------------- --- --- ------------------- -------------------
t_pk t yes no 03/22/2013 20:53:23
--下面尝试插入两条数据
scott@cnmmbo> insert into t select 1 from dual;
1 row created.
scott@cnmmbo> insert into t select 2 from dual;
1 row created.
--再次收集统计信息
scott@cnmmbo> exec dbms_stats.gather_table_stats('scott','t',cascade=>true);
pl/sql procedure successfully completed.
--author : robinson
--blog : -0612
--这下子,索引变成了已经被使用
scott@cnmmbo> select * from v$object_usage where index_name='t_pk';
index_name table name mon use start_monitoring end_monitoring
------------------------------ ------------------ --- --- ------------------- -------------------
t_pk t yes yes 03/22/2013 20:53:23