Oracle收集统计信息导致索引被监控


对于索引的调整,我们可以通过Oracle提供的索引监控特性来跟踪索引是否被使用。尽管该特性并未提供索引使用的频度,但仍不失为我们参考的方式之一。然而,最近在Oracle 10.2.0.3中发现收集统计信息时导致索引也被监控,而不是用于sql查询引发的索引监控。如此这般,索引监控岂不是鸡肋?

1、基于Oracle 10g 收集统计信息索引被监控情形

scott@CNMMBO> select * from v$version where rownum<2;

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  : http://blog.csdn.net/robinson-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

  • 1
  • 2
  • 下一页

相关内容