您的位置:首页 > 数据库 > Oracle

oracle重建、更新索引、索引统计信息命令

2013-09-06 14:32 435 查看
在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:收集[b]数据库[/b]中所有对象的统计信息;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: