如何监控Oracle索引的使用完全解析
来源:优易学  2010-1-11 17:37:10   【优易学:中国教育考试门户网】   资料下载   IT书店

 

2、oracle9i中如何确定索引的使用情况:

在oracle9i中,情况会简单得多,因为有一个新得字典视图V$SQL_PLAN存储了实际计划,这些计划用于执行共享SQL区中得语句。V$SQL_PLAN视图很类似与计划表,但V$SQL_PLAN使用ADDRESS和HASH_VALUE列 来识别语句, 而计划表使用用户提供得STATEMENT_ID来识别语句。下面的SQL显示了在一个oracle9i数据库中,由出现在共享SQL区中语句使用的所有索引。

  
    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;

所有基于共享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

上一页  [1] [2] 

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
热门课程培训