ITPub博客

首页 > 数据库 > 数据库开发技术 > 监控索引的使用(2)

监控索引的使用(2)

原创 数据库开发技术 作者:jss001 时间:2009-02-16 17:22:12 0 删除 编辑
  2、oracle9i中如何确定索引的使用情况
  在oracle9i中,情况会简单得多,因 为有一个新得字典视图V$SQL_PLAN存储了实际计划,这些计划用于执行共享SQL区中得语句。V$SQL_PLAN视图很类似与计划表,但 V$SQL_PLAN使用ADDRESS和HASH_VALUE列 来识别语句, 而计划表使用用户提供得STATEMENT_ID来识别语句。下面的SQL显示了在一个oracle9i数据库中,由出现在共享SQL区中语句使用的所有 索引
  [/code]
  select object_owner, object_name, options, count(*)
  from  v$sql_plan
  where operation='INDEX'
  and  object_owner!='SYS'
  group by object_owner, object_name, operation, options
  order by count(*) desc;
  [/code]
  
   所有基于共享SQL区中的信心来识别索引使用情况的方法, 都可能会收集到不完整的信息。共享SQL区是一 个动态结构,除非能对它进行足够频繁的采样, 否则在有关索引使用的情况的信息被收集之前,SQL语句可 能就已经(因为老化)被移出缓存了。oracle9i提供了解决这个问题的方案,即它为alter index提供了一个
  monitoring usage子句。当启用monitoring usage 时,oralce记录简单的yes或no值,以指出在监控间隔 期间某个索引是否被使用。
  
  为了演示这个新特性,你可以使用下面的例子:
  (a) Create and populate a small test table
  (b) Create Primary Key index on that table
  (c) Query v$object_usage: the monitoring has not started yet
  (d) Start monitoring of the index usage
  (e) Query v$object_usage to see the monitoring in progress
  (f) Issue the SELECT statement which uses the index
  (g) Query v$object_usage again to see that the index has been used
  (h) Stop monitoring of the index usage
  (i) Query v$object_usage to see that the monitoring sDetailed steps:
  
  (a) Create and populate a small test table
  create table products  (
  prod_id number(3),
  prod_name_code varchar2(5));
  
  insert into products values(1,'aaaaa');
  insert into products values(2,'bbbbb');
  insert into products values(3,'ccccc');
  insert into products values(4,'ddddd');
  commit;
  
  (b) Create Primary Key index on that table
  alter table products  add (constraint products_pk primary key (prod_id));
  
  (c) Query v$object_usage: the monitoring has not started yet
  column
如何监控索引的使用?  研究发现,oracle数据库使用的索引不会超过总数的25%,或者不易他们期望被使用的方式使用。通过 监控数据库索引的使用,释放那些未被使用的索引,从而节省维护索引的开销,优化性能。
  
[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18921899/viewspace-1017445/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 查找bad sql
请登录后发表评论 登录
全部评论
  • 博文量
    306
  • 访问量
    871823