DML性能低下,其中最严重的原因之一是无用索引的存在。所有SQL的插入,更新和删除操作在它们需要在每一行数据被改变时修改大量索引的时候会变得更慢。
许多Oracle 管理人员只要看见在一个SQL 查询的WHERE语句出现了一列的话就会为它分配索引。虽然这个方法能够让SQL运行得更快速,但是基于功能的Oracle 索引使得数据库管理人员有可能在数据表的行上过度分配索引。过度分配索引会严重影响关键Oracle 数据表的性能。
在Oracle9i出现以前,没有办法确定SQL查询没有使用的索引。让我们看看Oracle9i提供了什么样的方法让你找到这些索引并删除它们。
过程是相当简单的。Oracle9i有一个工具能够让你使用ALTER INDEX命令监视索引的使用。然后你可以查找这些没有使用的索引并从数据库里删除它们。
从Oracle 9i开始,可以监控Oracle索引的使用情况
具体方法如下:
alter index . MONITORING USAGE;
select owner,index_name from dba_indexeS where wner='HMP';
再生成monitor index 的SQL 脚本:
select 'alter index '||owner||'.'||index_name||' MONITORING USAGE;' from dba_indexes where owner in ('HMP');
也可以用下面方式生成多个用户monitor index 的SQL 脚本:
select 'alter index '||owner||'.'||index_name||' MONITORING USAGE;' from dba_indexes whereowner not in ('SYS','SYSTEM');
你需要等待一段时间(例如一个月)直到在数据库上运行了足够多的SQL语句以后,然后你就可以查询新的V$OBJECT_USAGE视图(进入monitor user )
select index_name, table_name, monitoring, used ,start_monitoring,end_monitoring from v$object_usage;
如果要查看所有用户下的被监控的索引的情况,使用如下SQL:
select
u.name owner,
io.name index_name,
t.name table_name,
decode(bitand(i.flags, 65536), 0, 'NO', 'YES') monitoring,
decode(bitand(ou.flags, 1), 0, 'NO', 'YES') used,
ou.start_monitoring start_monitoring,
ou.end_monitoring end_monitoring
from sys.user$ u,
sys.obj$ io,
sys.obj$ t,
sys.ind$ i,
sys.object_usage ou
where i.obj# = ou.obj#
and io.obj# = ou.obj#
and t.obj# = i.bo#
and u.user# = io.owner#;
如果要取消对索引使用情况的监控,使用下列SQL:
alter index . NOMONITORING USAGE;
再生成NOTmonitor index 的SQL 脚本:
select 'alter index '||owner||'.'||index_name||' NOMONITORING USAGE;' from dba_indexes where owner in ('HMP');
要注意的是:索引使用情况监控,会增加部分系统开销。
参考:http://space.itpub.net/13177610/viewspace-686392
http://haiery.**.com/blog/78313
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7583803/viewspace-690035/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7583803/viewspace-690035/