Chinaunix首页 | 论坛 | 博客
  • 博客访问: 210562
  • 博文数量: 78
  • 博客积分: 582
  • 博客等级: 下士
  • 技术积分: 560
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 09:06
文章分类

全部博文(78)

文章存档

2012年(50)

2011年(1)

2010年(27)

分类:

2010-10-20 21:26:01

DBMS_STATS.GATHER_TABLE_STATS详解

作用:DBMS_STATS.GATHER_TABLE_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是默认值,由决定最佳取采样值.

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

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

例子:

execute dbms_stats.gather_table_stats(ownname => 'owner',tabname => 'table_name' ,estimate_percent => null ,method_opt => 'for all indexed columns' ,cascade => true);

转自:http://space.itpub.net/7419833/viewspace-422844

exec dbms_stats.gather_table_stats('TBCS','TABLE_NAME',cascade => TRUE);
exec dbms_stats.gather_table_stats('TBCS','LARGE_TABLE_NAME',estimate_percent => 1,cascade => TRUE);---适用于大表
 select 'exec dbms_stats.gather_table_stats(' || chr(39) || 'TBCS' || chr(39) || ',' ||
       chr(39) || table_name || chr(39) || ',' || 'cascade => TRUE);'
  from user_tables;
 
生成执行脚本:
#!/bin/sh
sqlplus -s <set echo on
set heading on
set termout on
spool $1.log
@$1.sql;
spool off;
set echo off
set heading off
set termout off
exit;
EOF
阅读(1359) | 评论(0) | 转发(0) |
0

上一篇:Oracle的TM锁类型

下一篇:AIX添加DNS

给主人留下些什么吧!~~