收集统计信息


1)收集统计信息一般包括 

 

             1Table statistics

                        Number of rows

                        Number of blocks

                        Average row length

            2Column statistics

                        Number of distinct values (NDV) in column

                        Number of nulls in column

                        Data distribution (histogram)

            3Index statistics

                        Number of leaf blocks

                        Levels

                        Clustering factor

            4System statistics

                        I/O performance and utilization

                                          CPU performance and utilization

2)统计信息的收集

2.1常用的收集方式执行dbms_stats.gather包也可以用analyze tablename compute statistics

全库收集
exec dbms_stats.gather_database_stats(estimate_percent=>10,degree=>8,cascade=>true,granularity=>'ALL');


schema收集
exec dbms_stats.gather_schema_stats(ownname=>'SE',estimate_percent=>10,degree=>8,cascade=>true,granularity=>'ALL');


Table收集
exec dbms_stats.gather_table_stats(ownname=>'DW_HW_CHCH',tabname=>'表名',estimate_percent=>10,degree=>8,cascade=>true,granularity=>'ALL');


分区收集
exec dbms_stats.gather_table_stats(ownname=>'DW_HW_CHCH',tabname=>'表名',partname='分区名',estimate_percent=5,degree=>8,cascade=>true,granularity=>'PARTITION',method_opt>'FOR ALL INDEXED COLUMNS');


数据字典收集
exec dbms_stats.gather_dictionary_stats (estimate_percent=>100,degree=>8,cascade=>true,granularity=>'ALL');


动态性能表统计信息
exec dbms_stats.gather_fixed_objects_stats;




硬件统计信息收集
--典型业务开始前
exec dbms_stats.gather_system_stats('START');
--典型业务结束后

exec dbms_stats.gather_system_stats('STOP');

2.2参数说明:
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 <list> SIZE <N> | REPEAT | AUTO | SKEWONLY:
                                              统计指定列的histograms.N的取值范围[1,254]; R
                                              EPEAT上次统计过的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.
cascade:       是收集索引的信息.默认为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:         即使表锁住了也收集统计信息

2.3加锁解锁统计信息

--对于有些表或者用户的数据基本不怎么发生变化,如果每次收集时也将其收集一遍浪费资源,因此可以将这些表或者用户进行统计信息采集的锁定
exec dbms_stats.lock_table_stats('owner name','table name');


exec dbms_stats.lock_schema_stats ('schema name');
exec DBMS_STATS.LOCK_TABLE_STATS('SYS','T1');  


--通过unlock_table_stats   unlock_schema_stats 可以解锁


exec dbms_stats.unlock_table_stats(user,'表名')


DBMS_STATS.UNLOCK_schema_STATS(user);

3)统计信息的监看

3.1统计信息存储在下列数据字典中
·         DBA_TABLES
·         DBA_OBJECT_TABLES
·         DBA_TAB_STATISTICS
·         DBA_TAB_COL_STATISTICS
·         DBA_TAB_HISTOGRAMS
·         DBA_INDEXES
·         DBA_IND_STATISTICS
·         DBA_CLUSTERS
·         DBA_TAB_PARTITIONS
·         DBA_TAB_SUBPARTITIONS
·         DBA_IND_PARTITIONS
·         DBA_IND_SUBPARTITIONS
·         DBA_PART_COL_STATISTICS
·         DBA_PART_HISTOGRAMS
·         DBA_SUBPART_COL_STATISTICS
·         DBA_SUBPART_HISTOGRAMS
·         INDEX_STATS              存储ANALYZE ..VALIDATE STRUCTURE统计信息
·         AUX_STATS$               存储CPU统计信息
·         X$KCFIO                  存储I/O统计信息

3.2   表的统计信息:

            包含表行数,使用的块数,空的块数,块的使用率,行迁移和链接的数量,pctfreepctused的数据,行的平均大小:

 

    SELECT NUM_ROWS, --表中的记录数

        BLOCKS, --表中数据所占的数据块数

        EMPTY_BLOCKS, --表中的空块数

        AVG_SPACE, --数据块中平均的使用空间

        CHAIN_CNT, --表中行连接和行迁移的数量

        AVG_ROW_LEN --每条记录的平均长度

            FROM USER_TABLES

3.3   索引列的统计信息   

            包含索引的深度(B-Tree的级别),索引叶级的块数量,集群因子(clustering_factor), 唯一值的个数。

 

SELECT BLEVEL, --索引的层数

    LEAF_BLOCKS, --叶子结点的个数

    DISTINCT_KEYS, --唯一值的个数

    AVG_LEAF_BLOCKS_PER_KEY, --每个KEY的平均叶块个数

    AVG_DATA_BLOCKS_PER_KEY, --每个KEY的平均数据块个数

    CLUSTERING_FACTOR --群集因子

FROM USER_INDEXES

 

3.4   列的统计信息 

            包含 唯一的值个数,列最大小值,密度(选择率),数据分布(直方图信息),NUll值个数

 

SELECT NUM_DISTINCT, --唯一值的个数

    LOW_VALUE, --列上的最小值

    HIGH_VALUE, --列上的最大值

    DENSITY, --选择率因子(密度)

    NUM_NULLS, --空值的个数

    NUM_BUCKETS, --直方图的BUCKET个数

    HISTOGRAM --直方图的类型

FROM USER_TAB_COLUMNS

                        

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值