Oracle表与索引管理

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:135

1.分析表与索引
analyze table tablename compute statistics
等同于
analyze table tablename compute statistics for table for all indexes for all columns

analyze index 索引ID compute statistics;

2、一般来讲可以采用以下三种方式来手工分析索引。
analyze index idx_t validate structure:
analyze index idx_t compute statistics:
analyze index idx_t estimate statistics sample 10 percent

1)analyze index idx_t validate structure:
这段分析语句是用来分析索引的block中是否有坏块儿,那么根据分析我们可以得到索引的结构数据,这些数据会保留到
index_stats中,来判断这个索引是否需要rebuild. 需要注意的是这样的分析是不会收集索引的统计信息的。

2)validate structure有二种模式: online, offline, 一般来讲默认的方式是offline。
当以offline的模式analyze索引时,会对table加一个表级共享锁,对目前table的一些实时DMl操作会产生一定的影响。
而以online模式分析时候,则不会加任何lock,但在index_stats中是看不到任何信息的。

3)analyze index idx_t compute statistics:
用来统计索引的统计信息(全分析),主要为CBO服务。

4)analyze index idx_t estimate statistics sample 10 percent
主要是用来指定比例进行抽样分析,也是为CBO服务. 例中是抽样10%

3.重建索引
alter index index_name rebuild tablespace tablespace_name
alter index index_name rebuild tablespace tablespace_name 加入表空间名,会将指定的索引移动到指定的表空间当中。

4、其他的统计方法

--分析表
exec dbms_stats.gather_table_stats(ownname => USERNAME,tabname =>TABLENAME,estimate_percent => 10,method_opt=> 'for all indexed columns');

--分析索引
exec dbms_stats.gather_index_stats(ownname =>USERNAME,indname =>INDEX_NAME,estimate_percent => '10',degree => '4');

--如果发现执行计划走错,删除表的统计信息
exec dbms_stats.delete_table_stats(ownname =>USERNAME,tabname =>TABLENAME) ;

本文标签:
本文标题:Oracle表与索引管理
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】