Oracle收集統計資訊導致索引被監控

來源:互聯網
上載者:User

對於索引的調整,我們可以通過Oracle提供的索引監控特性來跟蹤索引是否被使用。儘管該特性並未提供索引使用的頻度,但仍不失為我們參考的方式之一。然而,最近在Oracle 10.2.0.3中發現收集統計資訊時導致索引也被監控,而不是用於sql查詢引發的索引監控。如此這般,索引監控豈不是雞肋?

1、基於Oracle 10g 收集統計資訊索引被監控情形

scott@CNMMBO> select * from v$version where rownum<2;

BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

--建立暫存資料表t
scott@CNMMBO> create table t(id number constraint t_pk primary key);

Table created.

--啟用索引監控
scott@CNMMBO> alter index t_pk monitoring usage;

Index altered.

--查看對象的使用方式
scott@CNMMBO> select * from v$object_usage where index_name='T_PK';

INDEX_NAME                    Table Name        MON USE START_MONITORING    END_MONITORING
------------------------------ ----------------- --- --- ------------------- -------------------
T_PK                          T                YES NO  03/22/2013 20:53:23

--收集表t上的統計資訊
scott@CNMMBO> exec dbms_stats.gather_table_stats('SCOTT','T',cascade=>true);

PL/SQL procedure successfully completed.

--下面的查詢中提示索引沒有被使用
--這應該是由於表上沒有資料的緣故,也就不存在對應的索引段
scott@CNMMBO> select * from v$object_usage where index_name='T_PK';

INDEX_NAME                    Table Name        MON USE START_MONITORING    END_MONITORING
------------------------------ ----------------- --- --- ------------------- -------------------
T_PK                          T                YES NO  03/22/2013 20:53:23

--下面嘗試插入兩條資料
scott@CNMMBO> insert into t select 1 from dual;

1 row created.

scott@CNMMBO> insert into t select 2 from dual;

1 row created.

--再次收集統計資訊
scott@CNMMBO> exec dbms_stats.gather_table_stats('SCOTT','T',cascade=>true);

PL/SQL procedure successfully completed.

--Author : Robinson
--Blog  : http://blog.csdn.net/robinson-0612

--這下子,索引變成了已經被使用
scott@CNMMBO> select * from v$object_usage where index_name='T_PK';

INDEX_NAME                    Table Name        MON USE START_MONITORING    END_MONITORING
------------------------------ ------------------ --- --- ------------------- -------------------
T_PK                          T                  YES YES 03/22/2013 20:53:23

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.