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

2014-11-24 18:05:38 · 作者: · 浏览: 1

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