您好,欢迎访问一九零五行业门户网

Oracle 索引监控与外键索引

oracle 监控索引特性为我们提供了一个大致判断索引是否被使用的情形。之所以这么说,是因为在oracle 10g 中收集统计信息时会导致
oracle 监控索引特性为我们提供了一个大致判断索引是否被使用的情形。之所以这么说,是因为在oracle 10g 中收集统计信息时会导致索引被监控,此并非sql语句而产生。而在11g则不会出现类型的情形。其次对于存在子表存在外键的情形,对于主表进行操作时是否会导致索引被监控呢?下面描述的是这个话题。
1、普通监控索引的情形
--演示环境
sql> select * from v$version where rownum
banner
--------------------------------------------------------------------------------
oracle database 11g enterprise edition release 11.2.0.1.0 - 64bit production
--创建主表 
sql> create table ptb(deptno number constraint ptb_pk primary key,dname varchar2(20));
table created.
--从scott.dept帐户复制数据
sql> insert into ptb select deptno,dname from dept;
4 rows created.
sql> commit;
commit complete.
--开启索引监控
sql> alter index ptb_pk monitoring usage;
--为主表收集统计信息
sql> exec dbms_stats.gather_table_stats('scott','ptb',cascade=>true);
pl/sql procedure successfully completed
sql> select * from v$object_usage where index_name='ptb_pk';
index_name                    table_name                mon use start_monitoring    end_monitoring
------------------------------ ------------------------- --- --- ------------------- -------------------
ptb_pk                        ptb                      yes no  03/22/2013 17:15:37
--注意上面的情形,收集统计信息时,索引被使用没有被监控到,,在10g中则会被监控到
--下面开启autotrace
sql> set autot trace exp;
sql> select * from ptb where deptno=10;
execution plan
----------------------------------------------------------
plan hash value: 3991869509
--------------------------------------------------------------------------------------
| id  | operation                  | name  | rows  | bytes | cost (%cpu)| time    |
--------------------------------------------------------------------------------------
|  0 | select statement            |        |    1 |    12 |    1  (0)| 00:00:01 |
|  1 |  table access by index rowid| ptb    |    1 |    12 |    1  (0)| 00:00:01 |
|*  2 |  index unique scan        | ptb_pk |    1 |      |    0  (0)| 00:00:01 |
--------------------------------------------------------------------------------------
sql> set autot off;
sql> select * from v$object_usage where index_name='ptb_pk'; --索引使用被监控到
index_name                    table_name                mon use start_monitoring    end_monitoring
------------------------------ ------------------------- --- --- ------------------- -------------------
ptb_pk                        ptb                      yes yes 03/22/2013 17:15:37
其它类似信息

推荐信息