dbms_stats


执行语句
dbms_stats.gather_schema_stats(User,estimate_percent=>100,cascade=> TRUE);
dbms_stats.gather_table_stats(User,TableName,degree => 4,cascade => true);

dbms_stats.create_stat_table:创建分析表
dbms_stats.delete_table_stats:删除分析信息
dbms_stats.gather_table_stats:分析表信息,当cascade为true时,分析表、列(索引)信息
dbms_stats.export_table_stats:导出表分析信息
dbms_stats.import_table_stats:导入表分析信息

dbms_stats.gather_index_stats:分析索引信息
dbms_stats.export_index_stats:导出索引分析信息
dbms_stats.import_index_stats:导入索引分析信息

dbms_stats.gather_schema_stats:分析方案信息
dbms_stats.export_schema_stats:导出方案分析信息
dbms_stats.import_schema_stats:导入方案分析信息

dbms_stats.gather_database_stats:分析数据库信息
dbms_stats.export_database_stats:导出数据库分析信息
dbms_stats.import_database_stats:导入数据库分析信息

dbms_stats.gather_system_stats:分析系统信息
dbms_stats.export_system_stats:导出系统分析信息
dbms_stats.import_system_stats:导入系统分析信息

dbms_stats.export_column_stats:导出列的分析信息
dbms_stats.import_column_stats:导入列分析信息

 


DBMS_STATS.GATHER_TABLE_STATS  的语法如下:
dbms_stats.gather_table_stats (ownname VARCHAR2,tabname VARCHAR2,partname VARCHAR2,estimate_percent NUMBER,block_sample BOOLEAN,method_opt VARCHAR2,degree NUMBER,granularity VARCHAR2,cascade BOOLEAN,stattab VARCHAR2,statid VARCHAR2,statown VARCHAR2,no_invalidate BOOLEAN,force BOOLEAN);
ownname:要分析表的拥有者
tabname:要分析的表名.
partname:分区的名字,只对分区表或分区索引有用.
estimate_percent:采样行的百分比,取值范围[0.000001,100],null为全部分析,不采样. 常量:DBMS_STATS.AUTO_SAMPLE_SIZE是默认值,由oracle决定最佳取采样值.
block_sapmple:是否用块采样代替行采样.
method_opt:决定histograms信息是怎样被统计的.method_opt的取值如下:
for all columns:统计所有列的histograms.
for all indexed columns:统计所有indexed列的histograms.
for all hidden columns:统计你看不到列的histograms
for columns SIZE | REPEAT | AUTO | SKEWONLY:统计指定列的histograms.N的取值范围[1,254]; REPEAT上次统计过的histograms;AUTO由oracle决定N的大小;SKEWONLY multiple end-points with the same value which is what we define by "there is skew in the data"
degree:决定并行度.默认值为null.
granularity:Granularity of statistics to collect ,only pertinent if the table is partitioned.
cascace:是收集索引的信息.默认为falase.
stattab:指定要存储统计信息的表,statid如果多个表的统计信息存储在同一个stattab中用于进行区分.statown存储统计信息表的拥有者.以上三个参数若不指定,统计信息会直接更新到数据字典.
no_invalidate: Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE.
force:即使表锁住了也收集统计信息.


DBMS_STATS.GATHER_SCHEMA_STATS  的语法如下:
dbms_stats.gather_schema_stats(
ownname => 'SCOTT',
options => 'GATHER AUTO',
estimate_percent => dbms_stats.auto_sample_size,
method_opt => 'for all columns size repeat',
degree => 15
)

options参数
使用4个预设的方法之一,这个选项能控制Oracle统计的刷新方式:
gather——重新分析整个架构(Schema)。
gather empty——只分析目前还没有统计的表。
gather stale——只重新分析修改量超过10%的表(这些修改包括插入、更新和删除)。
gather auto——重新分析当前没有统计的对象,以及统计数据过期(变脏)的对象。注意,使用gather auto类似于组合使用gather stale和gather empty。
注意,无论gather stale还是gather auto,都要求进行监视。如果你执行一个alter table xxx monitoring命令,Oracle会用dba_tab_modifications视图来跟踪发生变动的表。这样一来,你就确切地知道,自从上一次分析统计数据以来,发生了多少次插入、更新和删除操作。

estimate_percent选项
以下estimate_percent参数是一种比较新的设计,它允许Oracle的dbms_stats在收集统计数据时,自动估计要采样的一个segment的最佳百分比:
estimate_percent => dbms_stats.auto_sample_size
要验证自动统计采样的准确性,你可检视dba_tables sample_size列。一个有趣的地方是,在使用自动采样时,Oracle会为一个样本尺寸选择5到20的百分比。记住,统计数据质量越好,CBO做出的决定越好。

method_opt选项
method_opt=>'for all columns size skewonly'    skewonly选项,会耗费大量处理时间,因为它要检查每个索引中的每个列的值的分布情况
method_opt=>'for all columns size repeat'      repeat选项,重新分析任务所消耗的资源就会少一些,只会为现有的直方图重新分析索引
method_opt=>'for all columns size auto'     auto选项,根据数据分布以及应用程序访问列的方式

degree选项
并行度

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23577591/viewspace-703855/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23577591/viewspace-703855/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值