Oracle 對索引進行監控與分析

來源:互聯網
上載者:User

查看錶索引資訊 需要用到dba_indexes, dba_ind_columns,查看錶索引列資訊,包括複合索引的指令碼:

  1. WITH nonformat AS     
  2. (SELECT i.index_name,i.table_name,t.column_name,t.column_position,i.uniqueness,t.table_owner    
  3. FROM dba_indexes i, dba_ind_columns t    
  4. WHERE i.table_name = t.table_name    
  5.  AND i.table_owner = t.table_owner    
  6.  AND i.index_name = t.index_name    
  7.  AND i.table_name = upper('t')    
  8.  --AND i.table_owner = upper('scott')    
  9.  ORDER BY t.index_name,t.column_position     
  10.  )     
  11.  SELECT nt.index_name,    
  12.         nt.table_name,    
  13.         (SELECT wmsys.wm_concat(column_name)    
  14.            FROM nonformat    
  15.           WHERE nt.index_name = index_name) column_names,    
  16.         nt.uniqueness,    
  17.         nt.table_owner    
  18.    FROM nonformat nt    
  19.   GROUP BY nt.index_name, nt.table_name, nt.uniqueness, nt.table_owner    
  20.   ORDER BY nt.index_name    

索引列column_names以,分隔,需要指定表名與表的所有者資訊。

翻了幾頁書,做一下筆記哦!
發現多餘的索引有兩種方式
1.根據原理來判斷
  考慮複合索引,根據複合索引的首碼性與選擇性,分析表欄位的記錄分布情況,對複合索引進行整合。
2.使用Oracle的監控特性
alter index <index_name> monitoring usage; --對index_name開啟監控
alter index <index_name> nomonitoring usage; --對index_name取消監控
select * from v$object_usage; --查詢索引是否被使用 

  1. SQL> desc t  
  2. Name           Type          Nullable Default Comments   
  3. -------------- ------------- -------- ------- --------   
  4. OWNER          VARCHAR2(30)  Y                           
  5. OBJECT_NAME    VARCHAR2(128) Y                           
  6. SUBOBJECT_NAME VARCHAR2(30)  Y                           
  7. OBJECT_ID      NUMBER        Y                           
  8. DATA_OBJECT_ID NUMBER        Y                           
  9. OBJECT_TYPE    VARCHAR2(19)  Y                           
  10. CREATED        DATE          Y                           
  11. LAST_DDL_TIME  DATE          Y                           
  12. TIMESTAMP      VARCHAR2(19)  Y                           
  13. STATUS         VARCHAR2(7)   Y                           
  14. TEMPORARY      VARCHAR2(1)   Y                           
  15. GENERATED      VARCHAR2(1)   Y                           
  16. SECONDARY      VARCHAR2(1)   Y                           
  17. SQL> create index idx_t_created on t(created);  
  18. Index created  
  19. SQL> alter index idx_t_created monitoring usage;  
  20. Index altered  
  21. SQL> alter index idx_t_created nomonitoring usage;   
  22. Index altered  
  23. SQL> select * from v$object_usage;  
  24. INDEX_NAME                     TABLE_NAME                     MONITORING USED START_MONITORING    END_MONITORING  
  25. ------------------------------ ------------------------------ ---------- ---- ------------------- -------------------  
  26. IDX_T_CREATED                  T                              NO         NO   06/27/2011 21:31:56 06/27/2011 21:32:44  
  • 1
  • 2
  • 下一頁

相關文章

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.