分析oracle索引空間使用方式,以及索引是否需要重建,oracle索引

來源:互聯網
上載者:User

分析oracle索引空間使用方式,以及索引是否需要重建,oracle索引
分析索引空間使用方式,以及索引是否需要重建

分析其他使用者下的索引需要 analyze any的許可權
分析索引前先查看錶的大小和索引的大小,如果索引大小和表大小一樣大或者大於表的大小,那麼可以判斷索引可能有問題,需要分析索引
查詢對象大小:
select owner,segment_name,segment_type,bytes/1024/1024 from dba_segments order by 4 desc 

1.分析索引
SQL> analyze index AA.INDEX_AA validate structure;  
SQL> 
Index analyzed
 
查詢空間使用方式:

SQL> select name, blocks, lf_blks,  br_blks, blocks-(lf_blks+br_blks) empty from index_stats;
 
NAME                               BLOCKS    LF_BLKS    BR_BLKS      EMPTY
------------------------------ ---------- ---------- ---------- ----------
AA                                262144      253480        725       7939
--索引空塊達到了7939
 
2.查詢索引刪除行和刪除比例(一般刪除率達到30%就要考慮重建索引)
SQL> select t.name, --索引名
  2          t.lf_rows, --number of leaf rows (values in the index)
  3          t.lf_blks,
  4          t.del_lf_rows, --number of deleted leaf rows in the index
  5          (t.del_lf_rows / t.lf_rows)*100 ratio --刪除比例
  6     from index_stats t
  7     where t.name='INDEX_AA';
 
NAME                              LF_ROWS    LF_BLKS DEL_LF_ROWS      RATIO
------------------------------ ---------- ---------- ----------- ----------
AA                              77318533     253480           0          0
 
3.查看索引的使用率以及索引深度(深度>=4時就考慮重建索引)
SQL> SELECT height, NAME, BTREE_SPACE, USED_SPACE, PCT_USED FROM INDEX_STATS;
 
    HEIGHT NAME                           BTREE_SPACE USED_SPACE   PCT_USED
---------- ------------------------------ ----------- ---------- ----------
         4 INDEX_AA                       2032646380 1231201944         61
--索引深度為4
滿足下列條件考慮重建索引
The most common justifications given for rebuilding an index are:
- index becomes fragmented
- index grows and grows - deleted space is not re-used
- index clustering factor becomes out of sync
oracle索引問題,刪除再重建索引與索引分析

1. 應該是可行的, 具體 會不會節省時間 試一下就可以了。

2. 大概每個月儲存四五十萬的資料,裡面只儲存最新四個月的資料

每次create這7個索引用時都特別長,大概需要三四個小時;

200萬的資料,重建索引花費的時間太長了;很奇怪。

3. 估計之前的 先drop掉索引,然後插入資料完畢後create索引 也是為了避免 插入資料時,索引對插入效率的影響。
 
分析索引與重建主鍵索引

validate structure應該是用來填充index_stats視圖,而compute statistics 填充user_indexes(這個視圖在後來oracle建議使用user_ind_statistics來代替),前者注重結構統計資訊,而後者一般是對整個索引的狀態進行統計(根據兩個視圖的不同欄位可以看出區別)。

主鍵索引和其它索引沒有什麼區別,只是列上加了一個unique約束和一個unique索引而已,所以分析索引只要和其它列上索引一樣分析就行了。
 

相關文章

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.