ORACLE DBMS_STATS统计信息搜集

ORACLE DBMS_STATS统计信息搜集

1、收集数据库信息

--收集数据库信息

exec dbms_stats.gather_database_stats;

exec dbms_stats.gather_database_stats(estimate_percent => 15);

2、收集schema信息

--收集schema信息

exec dbms_stats.gather_schema_stats('scott');

exec dbms_stats.gather_schema_stats('scott', estimate_percent => 15);

3、收集表信息

--收集表信息

exec dbms_stats.gather_table_stats('scott', 'employees');

exec dbms_stats.gather_table_stats('scott', 'employees', estimate_percent => 15);

4、收集index信息

--收集index信息

exec dbms_stats.gather_index_stats('scott', 'employees_pk');

exec dbms_stats.gather_index_stats('scott', 'employees_pk', estimate_percent => 15);

5、删除收集信息

--删除收集信息

exec dbms_stats.delete_database_stats;

exec dbms_stats.delete_schema_stats('scott');

exec dbms_stats.delete_table_stats('scott', 'employees');

exec dbms_stats.delete_index_stats('scott', 'employees_pk');

6、创建备份收集信息表

--创建备份收集信息表

begin

	dbms_stats.create_stat_table(user,stattab => 'stat_table');

end;

7、备份收集信息

--备份收集信息

begin

dbms_stats.export_table_stats(user,tabname => 'employees',stattab => 'stat_table');

end;

8、删除收集信息

--删除收集信息

begin

dbms_stats.delete_table_stats(user,tabname => 'employees');

end;

9、导入收集信息

--导入收集信息

begin

dbms_stats.import_table_stats(user,'fei_t',stattab => 'stat_table');

end;

9、参数说明

DBMS_STATS.GATHER_TABLE_STATS (
   ownname          VARCHAR2, 
   tabname          VARCHAR2, 
   partname         VARCHAR2 DEFAULT NULL,
   estimate_percent NUMBER   DEFAULT to_estimate_percent_type 
                                                (get_param('ESTIMATE_PERCENT')), 
   block_sample     BOOLEAN  DEFAULT FALSE,
   method_opt       VARCHAR2 DEFAULT get_param('METHOD_OPT'),
   degree           NUMBER   DEFAULT to_degree_type(get_param('DEGREE')),
   granularity      VARCHAR2 DEFAULT GET_PARAM('GRANULARITY'), 
   cascade          BOOLEAN  DEFAULT to_cascade_type(get_param('CASCADE')),
   stattab          VARCHAR2 DEFAULT NULL, 
   statid           VARCHAR2 DEFAULT NULL,
   statown          VARCHAR2 DEFAULT NULL,
   no_invalidate    BOOLEAN  DEFAULT  to_no_invalidate_type (
                                     get_param('NO_INVALIDATE')),
   stattype         VARCHAR2 DEFAULT 'DATA',
   force            BOOLEAN  DEFAULT FALSE);

参数说明:

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:是收集索引的信息.默认为false.

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:即使表锁住了也收集统计信息.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值