链接:http://blog.itpub.net/28602568/viewspace-1429058/

标题:Oracle 真的有参数可以 1s 统计完 200G用户下的所有对象么?

作者:lōττéry©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]



注释:
  今天叫我同事统计一个200G用户,刚刚说完话,他随后不到1分钟说统计完了..
  他执行的语句: BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME => 'user1' ,options => 'GATHER AUTO' ,cascade => TRUE ,no_invalidate=> false); END ;
  和我往常统计语句不同的是多了一段"options => 'GATHER AUTO' "  
那我们解析来下为啥(默认)不写时,200G的用户要统计1个小时,加了这个属性1s 就统计完成呢?
Oracle自带dbms_stats.gather_schema_stats存储信息如下:
     procedure gather_schema_stats
        (ownname varchar2 ,
         estimate_percent number default DEFAULT_ESTIMATE_PERCENT,
         block_sample boolean default FALSE,
         method_opt varchar2 default DEFAULT_METHOD_OPT,
         degree number default to_degree_type(get_param( 'DEGREE' )),
         granularity varchar2 default DEFAULT_GRANULARITY,
         cascade boolean default DEFAULT_CASCADE,
         stattab varchar2 default null, statid varchar2 default null,
         options varchar2 default 'GATHER', statown varchar2 default null ,
         no_invalidate boolean default
           to_no_invalidate_type(get_param( 'NO_INVALIDATE' )),
         gather_temp boolean default FALSE,
         gather_fixed boolean default FALSE,
         stattype varchar2 default 'DATA',
         force boolean default FALSE ,
         obj_filter_list ObjectTab default null );
    --
    -- Input arguments:
    --   ownname - schema to analyze (NULL means current schema)
    --   estimate_percent - Percentage of rows to estimate (NULL means compute).
    --      The valid range is [0.000001,100].  Use the constant
    --      DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the
    --      appropriate sample size for good statistics. This is the default.
    --      The default value can be changed using set_param procedure.
    --   block_sample - whether or not to use random block sampling instead of
    --      random row sampling.  Random block sampling is more efficient, but
    --      if the data is not randomly distributed on disk then the sample values
    --      may be somewhat correlated.  Only pertinent when doing an estimate
    --      statistics.
    --   method_opt - method options of the following format
    --
    --         method_opt  := FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
    --
    --         size_clause := SIZE [integer | auto | skewonly | repeat],
    --                        where integer is between 1 and 254
    --
    --      default is FOR ALL COLUMNS SIZE AUTO.
    --      The default value can be changed using set_param procedure.
    --      This value will be passed to all of the individual tables.
    --   degree - degree of parallelism (NULL means use table default value which
    --      is specified by DEGREE clause in CREATE/ALTER TABLE statement)
    --      Use the constant DBMS_STATS.DEFAULT_DEGREE for the default value
    --      based on the initialization parameters.
    --      default for degree is NULL.
    --      The default value can be changed using set_param procedure.
    --   granularity - the granularity of statistics to collect (only pertinent
    --      if the table is partitioned)
    --     'AUTO' - the procedure determines what level of statistics to collect
    --     'GLOBAL AND PARTITION' - gather global- and partition-level statistics
    --     'SUBPARTITION' - gather subpartition-level statistics
    --     'PARTITION' - gather partition-level statistics
    --     'GLOBAL' - gather global statistics
    --     'ALL' - gather all (subpartition, partition, and global) statistics
    --     default for granularity is AUTO.
    --     The default value can be changed using set_param procedure.
    --   cascade - gather statistics on the indexes as well.
    --      Use the constant DBMS_STATS.AUTO_CASCADE to have Oracle determine
    --      whether index stats to be collected or not. This is the default.
    --      The default value can be changed using set_param procedure.
    --      Using this option is equivalent to running the gather_index_stats
    --      procedure on each of the indexes in the schema in addition to
    --      gathering table and column statistics.
    --   stattab - The user stat table identifier describing where to save
    --      the current statistics.
    --   statid - The (optional) identifier to associate with these statistics
    --      within stattab.
    --   options - further specification of which objects to gather statistics for
    --      'GATHER' - gather statistics on all objects in the schema
    --      'GATHER AUTO' - gather all necessary statistics automatically.  Oracle
    --        implicitly determines which objects need new statistics, and
    --        determines how to gather those statistics.  When 'GATHER AUTO' is
    --        specified, the only additional valid parameters are ownname, stattab,
    --        statid, objlist and statown; all other parameter settings will be
    --        ignored.  Also, return a list of objects processed.
    --      'GATHER STALE' - gather statistics on stale objects as determined
    --        by looking at the *_tab_modifications views.  Also, return
    --        a list of objects found to be stale.
    --      'GATHER EMPTY' - gather statistics on objects which currently
    --        have no statistics.  also, return a list of objects found
    --        to have no statistics.
    --      'LIST AUTO' - return list of objects to be processed with 'GATHER AUTO'
    --      'LIST STALE' - return list of stale objects as determined
    --        by looking at the *_tab_modifications views
    --      'LIST EMPTY' - return list of objects which currently
    --        have no statistics
    --   objlist - list of objects found to be stale or empty
    --   statown - The schema containing stattab (if different then ownname)
    --   no_invalidate - Do not invalide the dependent cursors if set to TRUE.
    --     The procedure invalidates the dependent cursors immediately
    --     if set to FALSE.
    --     Use DBMS_STATS.AUTO_INVALIDATE to have oracle decide when to
    --     invalidate dependend cursors. This is the default. The default
    --     can be changed using set_param procedure.
    --     When 'cascade' option is specified, not pertinent with certain types
    --     of indexes described in the gather_index_stats section.
    --   gather_temp - gather stats on global temporary tables also.  The
    --     temporary table must be created with "on commit preserve rows" clause,
    --     and the statistics being collected are based on the data in the session
    --     which this procedure is run but shared across all the sessions.
    --   gather_fixed - Gather statistics on fixed tables also.
    --     Statistics for fixed tables can be collected only by user SYS.
    --     Also the ownname should be SYS or NULL.
    --     Specified values for the following arguments will be ignored while
    --     gathering statistics for fixed tables.
    --       estimate_percent, block_sample, stattab, statid, statown
    --     It will not invalidate the dependent cursors on fixed table
    --     on which stats is collected.
    --     This option is meant for internal use only.
    --   force - gather statistics of objects even if they are locked.
    --   obj_filter_list - a list of object filters. When provided, gather_schema_stats
    --     will only gather statistics on the objects which satisfy at least one
    --     object filter in the list as needed. Please refer to obj_filter_list
    --     in  gather_database_stats.
    -- Exceptions:
    --   ORA-20000: Schema does not exist or insufficient privileges
    --   ORA-20001: Bad input value
    --   ORA-20002: Bad user statistics table, may need to upgrade it

************
options参数

gather    ——  重新剖析整个架构(Schema)
  gather empty —— 只剖析目前还没有统计的表。
  gather stale   —— 只重新剖析修改量超过10%的表(这些修改包含拔出、更新和删除)。
  gather auto    —— 重新剖析以后没有统计的对象,以及统计数据过期(变脏)的对象. 
注意,使用gather auto相似于组合使用gather stale和gather empty。
 例如:create table t as select * from dba_objects;(10w数据的话,insert = 1w数据(等于10%) gather auto 统计后还是10w数据,而默认的gather统计后是  ≈ 11w)
               但当10w数据,insert = 1w ,delete =1条 (求和 >10% ) 用 gather auto 统计和gather 都是一样的...
(测试:
SQL > SELECT T.TABLE_NAME,T.NUM_ROWS FROM USER_TABLES T WHERE TABLE_NAME=upper ('t_1' );
TABLE_NAME                       NUM_ROWS
------------------------------ ----------------------
T_1                                     100000
SQL > insert into t_1   select * from dba_objects where rownum <=10000 ;
10000 rows inserted
SQL >
SQL > BEGIN
2   DBMS_STATS.GATHER_SCHEMA_STATS(
3   OWNNAME => 'user1' ,
4   options => 'GATHER AUTO' ,
5   cascade => TRUE
6    );
7   END ;
8   /
PL /SQL procedure successfully completed
SQL > SELECT T.TABLE_NAME,T.NUM_ROWS FROM USER_TABLES T WHERE TABLE_NAME=upper ('t_1' );
TABLE_NAME                       NUM_ROWS
------------------------------ --------------------------
T_1                                      100000    --&gt 增量 = 10% ,用'GATHER AUTO'统计没变化
SQL > delete from t_1 where rownum <= 1 ;     --&gt 任意操作一条就证明  >  10% ,用'GATHER AUTO'统计 应该和默认一样~ 
1 row deleted
SQL >
SQL > BEGIN
2   DBMS_STATS.GATHER_SCHEMA_STATS(
3   OWNNAME => 'user1' ,
4   options => 'GATHER AUTO' ,
5   cascade => TRUE
6    );
7   END ;
8   /
PL /SQL procedure successfully completed
SQL > SELECT T.TABLE_NAME,T.NUM_ROWS FROM USER_TABLES T WHERE TABLE_NAME=upper ('t_1' );
TABLE_NAME                       NUM_ROWS
------------------------------ ------------------------------
T_1                                     109999
SQL >
所以,也就证明了,使用BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME => 'user1' ,options => 'GATHER AUTO' ,cascade => TRUE ,no_invalidate=> false); END ;
     统计用户1s就完成是因为USER1 用户下没有满足   options => 'GATHER AUTO' 属性  -- (修改量超过10%的表(这些修改包含拔出、更新和删除)或 没统计的表) 
     而往常使用 BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(OWNNAME => 'user1' ,options => 'GATHER' (default),cascade => TRUE ,no_invalidate=> false); END ; 
     统计要花1小时,是因为 针对整个200G用户 重新统计 ...
     
话说大家看到这,是否觉得自己受骗了捏~ 是的,骗了大家看完整个文章, 早知道的当复习找错啦哦~ 不知道options => 'GATHER AUTO'的也算简单了解了哈~~
     同时大家也仔细考虑好,统计选择那个参数更适合自己的环境,满足自己的需求~~~


    【源于本人笔记】 若有书写错误,表达错误,请指正...


此条目发表在 Oracle 分类目录。将固定连接加入收藏夹。

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

转载于:http://blog.itpub.net/28602568/viewspace-1429058/

Oracle 真的有参数可以 1s 统计完 200G用户下的所有对象么?相关推荐

  1. oracle expdp sys用户,Oracle基础教程:expdp时不能导出sys用户下的对象

    Oracle基础教程:expdp时不能导出sys用户下的对象 sys用户下的对象不支持导出 SQL> select owner,segment_name,tablespace_name from ...

  2. Oracle——删除用户以及用户下数据

    Oracle中删除用户下所有对象的多种方法 2015-09-22 13:12  8299人阅读  评论(0)  收藏  举报   分类: Oracle数据库基本管理(336)   oracle安装升级 ...

  3. linux安装oracle 操作系统内核参数 aio,Linux安装Oracle 11G过程(测试未写完)

    一.简介 Oracle数据库在系统运维中的重要性不言而喻,通过熟悉Oracle的安装来加深对操作系统和数据库知识的了解.Linux安装Oracle前期修改linux内核参数很重要,其实就是linux下 ...

  4. Oracle 11.2 参数详解

    #O7_DICTIONARY_ACCESSIBILITY是用来控制select any table权限是否可以访问data dictionary的,主要用来保护数据字典.oracle建议把O7_DIC ...

  5. Oracle并发(CONCURREMT)收集统计信息 (文档 ID 1555451.1)

    Oracle并发(CONCURREMT)收集统计信息 (文档 ID 1555451.1) 编辑手记:从11.2开始,可以通过CONCURRENT参数,启用表或分区的并行扫描,加快统计信息的收集速度. ...

  6. oracle GoldenGate 的参数配置

    1       GoldenGate简要说明 GoldenGate现在是业内成熟的数据容灾与复制产品,经过多年的发展与完善,现在已经成为业内事实上的标准之一. GoldenGate软件是一种基于日志的 ...

  7. linux下oracle数据库由于参数文件丢失导致的数据库服务启动失败,报“failure in processing system parameters“错误问题解决

    ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/data/o ...

  8. 利用Oracle内置分析函数进行高效统计汇总

    利用Oracle内置分析函数进行高效统计汇总 分析函数是Oracle从8.1.6开始引入的一个新的概念,为我们分析数据提供了一种简单高效的处理方式.在分析函数出现以前,我们必须使用自联查询,子查询或者 ...

  9. 学完oracle 再学mysql_一篇文章让Oracle程序猿学会MySql【未完待续】

    一篇文章让Oracle DB学会MySql[未完待续] 随笔前言: 本篇文章是针对已经能够熟练使用Oracle数据库的DB所写的快速学会MySql,为什么敢这么说,是因为本人认为Oracle在功能性方 ...

最新文章

  1. 使用Python,OpenCV检测摄像机到标记对象的距离
  2. MapReduce编程系列 — 2:计算平均分
  3. 初级程序员面试不靠谱指南(六)
  4. 剪板机自动上下料_机器人联轴器,用于机器人自动化上下料
  5. 我们为什么要学数学?这里给你一个答案。
  6. jquery常用技巧及常用方法列表
  7. OC中解析对象(json)
  8. Vue前端路由~非常详细哦,不要错过
  9. [转载] Python的双端队列deque
  10. jar包add to build path与放入lib下
  11. php mysql上机题_基于PHP+MySQL的题库管理系统
  12. source insight护眼模式颜色
  13. 安装Hadoop2.10.1
  14. jQuery fadeIn淡入效果
  15. 中国科学技术大学计算机考研好考吗,中国科学技术大学计算机考研复习方法谈(2)...
  16. ddl是什么意思网络语_跟随你大学的流行词语 DDL 你竟还不知道?
  17. 达梦数据库 防火墙设置
  18. c语言编程顺序查找法,建立顺序表,实现顺序表的遍历,在顺序表中查找关键字为e的元素(c语言编写)...
  19. wxpython使用多进程_最简单方法远程调试Python多进程子程序
  20. 几种修复照片画质的方法

热门文章

  1. Linux安装配置Git
  2. 算法 - 局部最优的避免
  3. [黑科技] 发现了一个Amazon黑科技插件,可以查看亚马逊卖家邮箱和电话。
  4. 一个基于Rxjava2+MVP的自定义文本阅读器
  5. 知乎上最好的项目管理书单!推荐收藏
  6. 视频教程-微信小程序界面设计-样式入门到精通-微信开发
  7. 数据泵(一)-基本概念
  8. 关于引起stop:c000021a unknown hard error部分问题及解决。
  9. 用Oracle数据泵还原库
  10. Android 获取视频缩略图