oracle重建、更新索引、索引統計信息命令


          在oracle中查找所有的表的索引的命令

 

     select t.*,i.index_type 
     from user_ind_columns t,user_indexes i
     where t.index_name = i.index_name and t.table_name = i.table_name

 

          在oracle中實現索引的批量重建的sql命令,其中TableSpace為索引表空間

 

Declare 
    L_Sql Varchar2(32767) := '';
Begin
    For indexRow In 
    (
        Select * 
        From user_indexes 
        Where tablespace_name = 'TableSpace' and status = 'VALID' And Temporary = 'N'
    ) 
    Loop
           L_Sql := 'alter index ' || indexRow.index_name || ' rebuild ';
           dbms_output.put_line(L_Sql);
           EXECUTE IMMEDIATE L_Sql;         
    End Loop;
End;

    
       分析單個表的索引的統計分析信息,其中tablename為具體表名稱

 

 

analyze table tablename compute statistics for all indexes;
analyze table tablename delete statistics 

 

        分析整個表空間的索引的統計信息,其中tablespace_name為具體的表空間名稱

 

Declare 
	L_Sql Varchar2(32767) := '';
Begin
    For tableRow In 
    (
        SELECT *
        from user_tables
        where tablespace_name = 'EDU_DATA'
    ) 
    Loop
           L_Sql := 'analyze table ' || tableRow.table_Name || ' compute statistics for all indexes ';
           dbms_output.put_line(L_Sql);
           EXECUTE IMMEDIATE L_Sql;         
    End Loop;
end;


 

         dbstatc包統計分析參數和說明,dbstatc包中用於收集統計信息的過程包括:

 

dbms_stats.gather_table_stats  收集表、列和索引的統計信息;

dbms_stats.gather_schema_stats   收集SCHEMA下所有對象的統計信息;

dbms_stats.gather_index_stats  收集索引的統計信息;

dbms_stats.gather_system_stats  收集系統統計信息。

dbms_stats.delete_table_stats  刪除表的統計信息

dbms_stats.export_table_stats 輸出表的統計信息

dbms_stats.create_state_table

dbms_stats.set_table_stats 設置 表的統計

dbms_stats.auto_sample_size

dbms_stats.gather_database_stats:收集數據庫中所有對象的統計信息;

 




 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM