所以说,没有被使用过的index在数据库中一定是低效,具有负面影响的,我们通过对索引的监控来查看索引是否在监控的时间段内被使用过。
索引监控:
alter index index_name monitoring usage;
查看是否在開始监控后被使用过:
select * from v$object_usage;
停止索引监控:
alter index index_name nomonitoring usage;
以下通过实验看一下:
SQL> create table t_id as select rownum id from dual connect by level<10000;
Table created
SQL> create index ind_t_id on t_id(id);
Index created
SQL> alter index ind_t_id monitoring usage;
Index altered
SQL> select * from v$object_usage where index_name='IND_T_ID';
INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
------------------------------ ------------------------------ ---------- ---- ------------------- -------------------
IND_T_ID T_ID YES NO 04/24/2014 13:27:39
SQL> select * from t_id where id=999;
ID
----------
999
SQL> select * from v$object_usage where index_name='IND_T_ID';
INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
------------------------------ ------------------------------ ---------- ---- ------------------- -------------------
IND_T_ID T_ID YES YES 04/24/2014 13:27:39
SQL> alter index ind_t_id nomonitoring usage;
Index altered
SQL> select * from v$object_usage where index_name='IND_T_ID';
INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
------------------------------ ------------------------------ ---------- ---- ------------------- -------------------
IND_T_ID T_ID NO YES 04/24/2014 13:27:39 04/24/2014 13:29:13