索引对于在大量数据里检索出少量数据库的查询操作来说是高效的,但是对于DML操作来说,却是负面的:①其对于insert 操作的反面影响最大,该表的索引越多,更新的索引越多,insert 操作越慢。②对于delete来说,大量数据定位删除少量数据的时候,通过索引定位删除是高效的,但如果删除数据量过多,或者有过多列有索引的时候,其他索引列因为数据的删除有会更新来说,索引是负面的。③对于update的负面影响最小,具体修改某一列时只会更新该列上的index。
所以说,没有被使用过的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
所以说,没有被使用过的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