ORACLE索引失效,更新統計資料

來源:互聯網
上載者:User

標籤:tab   rom   失效   執行計畫   TE   call   for   索引   統計資訊   

有時候建立索引的時候不走索引,排除了欄位資料問題和sql寫法問題之外,應該是統計資訊有問題,得重新收集。

一:解鎖統計資訊

為了穩定執行計畫,一般統計資訊都會被鎖住的,在更新統計資料的時候得先解鎖。①按使用者schema解鎖:EXEC DBMS_STATS.UNLOCK_schema_STATS(‘user_name‘);②按表模式解鎖:先查出被鎖定的表select table_name from user_tab_statistics where stattype_locked is not null;然後exec dbms_stats.unlock_table_stats(‘user_name‘,‘表名‘);

二:收集統計資訊方法:

1.分析表

begin    dbms_stats.gather_table_stats (    ownname          => ‘TEST‘,    tabname          => ‘STUDENT‘,    estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,    degree           => 4,    cascade          => TRUE);end;

2.分析使用者

begin    dbms_stats.gather_schema_stats(ownname          => ‘TEST‘,estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,degree           => 4,cascade          => TRUE);end;

3.分析索引

begin    dbms_stats.gather_index_stats(    ownname          => ‘TEST‘,    indname          => ‘IDX_STUDENT_BIRTH‘,    estimate_percent => dbms_stats.AUTO_SAMPLE_SIZE,    degree           => 4);end;還可以用analyze 來分析,例如:ANALYZE TABLE  (table_name) COMPUTE STATISTICS;  --分析表ANALYZE TABLE  (table_name) COMPUTE STATISTICS FOR ALL INDEXED COLUMNS;   --分析索引列ANALYZE TABLE  (table_name) COMPUTE STATISTICS FOR ALL INDEXES FOR ALL INDEXED COLUMNS;  --分析索引和索引列三:更新完統計資訊後得重新鎖住。CALL DBMS_STATS.LOCK_TABLE_STATS(‘user_name‘,‘table_name‘);

ORACLE索引失效,更新統計資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.