SQL> select * from v$version;



BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

PL/SQL Release 11.2.0.1.0 - Production

CORE    11.2.0.1.0      Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production





SQL> --制造一些数据

SQL> drop table test purge;

SQL> create table test as select * from dba_objects;

SQL> update test set object_id=2;

SQL> update test set object_id=1 where rownum=1;

SQL> commit;

SQL> create index ind_t_object_id on test(object_id);

SQL> exec dbms_stats.gather_table_stats(user,'test',cascade => true);

SQL> --看看数据的分布

SQL> select object_id,count(1) from test group by object_id;

 OBJECT_ID   COUNT(1)

---------- ----------

         1          1

         2      72415



SQL> set autotrace traceonly

SQL> --应该是要走索引

SQL> select * from test where object_id = 1;

运行计划

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      | 36208 |  3359K|   290   (1)| 00:00:04 |

|*  1 |  TABLE ACCESS FULL| TEST | 36208 |  3359K|   290   (1)| 00:00:04 |

--------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - filter("OBJECT_ID"=1)

统计信息

----------------------------------------------------------

          1  recursive calls

          0  db block gets

       1039  consistent gets

          0  physical reads

          0  redo size

       1191  bytes sent via SQL*Net to client

        338  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed





SQL> --应该是要走全表扫描

SQL> select * from test where object_id = 2;

已选择72415行。

运行计划

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      | 36208 |  3359K|   290   (1)| 00:00:04 |

|*  1 |  TABLE ACCESS FULL| TEST | 36208 |  3359K|   290   (1)| 00:00:04 |

--------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - filter("OBJECT_ID"=2)

统计信息

----------------------------------------------------------

          1  recursive calls

          0  db block gets

       5799  consistent gets

          0  physical reads

          0  redo size

    2940934  bytes sent via SQL*Net to client

      53435  bytes received via SQL*Net from client

       4829  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

      72415  rows processed



SQL> set autotrace off

SQL> col TABLE_NAME format a10;

SQL> col COLUMN_NAME format a10;

SQL> col ENDPOINT_ACTUAL_VALUE  format a10;

SQL> col ENDPOINT_NUMBER  format 9999999;

SQL> col ENDPOINT_VALUE  format 999999;

SQL>--直方图有问题,又一次收集直方图

SQL> select * from user_tab_histograms s where s.table_name='TEST' and column_name='OBJECT_ID';

TABLE_NAME COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A

---------- ---------- --------------- -------------- ----------

TEST       OBJECT_ID             0              1

TEST       OBJECT_ID             1              2

SQL> exec dbms_stats.gather_table_stats(user, 'test',cascade=>true, method_opt=>'for columns object_id size 2');



SQL> set autotrace traceonly

SQL> --还是不正确

SQL> select * from test where object_id = 1;

运行计划

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      | 36208 |  3359K|   290   (1)| 00:00:04 |

|*  1 |  TABLE ACCESS FULL| TEST | 36208 |  3359K|   290   (1)| 00:00:04 |

--------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - filter("OBJECT_ID"=1)

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

       1039  consistent gets

          0  physical reads

          0  redo size

       1191  bytes sent via SQL*Net to client

        338  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed





SQL> set autotrace off

SQL> select * from user_tab_histograms s where s.table_name='TEST' and column_name='OBJECT_ID';

TABLE_NAME COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A

---------- ---------- --------------- -------------- ----------

TEST       OBJECT_ID             5391              2





SQL> --仅仅实用analyze收集直方图

SQL> analyze table test compute statistics for table for columns object_id size 2;



SQL> select * from user_tab_histograms s where s.table_name='TEST' and column_name='OBJECT_ID';

TABLE_NAME COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A

---------- ---------- --------------- -------------- ----------

TEST       OBJECT_ID                1              1

TEST       OBJECT_ID            72416              2



SQL> set autotrace traceonly

SQL> select * from test where object_id = 1;

运行计划

----------------------------------------------------------

Plan hash value: 255872589

-----------------------------------------------------------------------------------------------

| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                 |     1 |    99 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| TEST            |     1 |    99 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IND_T_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |

-----------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   2 - access("OBJECT_ID"=1)

统计信息

----------------------------------------------------------

          1  recursive calls

          0  db block gets

          4  consistent gets

          0  physical reads

          0  redo size

       1191  bytes sent via SQL*Net to client

        338  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed





SQL> select * from test where object_id = 2;

运行计划

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      | 72415 |  7001K|   290   (1)| 00:00:04 |

|*  1 |  TABLE ACCESS FULL| TEST | 72415 |  7001K|   290   (1)| 00:00:04 |

--------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - filter("OBJECT_ID"=2)

统计信息

----------------------------------------------------------

          1  recursive calls

          0  db block gets

       5799  consistent gets

          0  physical reads

          0  redo size

    2940934  bytes sent via SQL*Net to client

      53435  bytes received via SQL*Net from client

       4829  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

      72415  rows processed

SQL> set autotrace off

在Oracle 11.2.0.1.0下dbms_stats.gather_table_stats收集直方图不准的更多相关文章

  1. Maven 下添加oracle11g的包 报Missing artifact com.oracle:ojdbc6:jar:11.2.0.1.0

    Missing artifact com.oracle:ojdbc6:jar:11.2.0.1.0 原因:Oracle 的ojdbc.jar是收费的,所以maven的中央仓库中没有这个资源,只能通过配 ...

  2. Oracle 11.2.0.4 RAC安装最新PSU补丁

    环境:两节点RAC(RHEL 6.4 + GI 11.2.0.4 + Oracle 11.2.0.4) 需求:安装最新PSU补丁11.2.0.4.7 1.下载补丁和最新OPatch 2.检查数据库当前 ...

  3. Oracle 11.2.0.4 DataGuard 环境打PSU,OJVM PSU补丁快速参考

    环境:RHEL6.5 + Oracle 11.2.0.4 DataGuard physical standby 主库和备库都是单节点. 需求:主备库同时应用160719的PSU和OJVM PSU补丁. ...

  4. Discoverer 11.1.1.3.0以Oracle Application用户登录的必要配置

    客户这边要使用Discoverer来出报表, 就从OTN上下载安装了11.1.1.3.0版本的, 安装很简单, 一路Next, 使用的EBS版本是12.1.1.3, 结果发现用Oracle Appli ...

  5. ORACLE LINUX 6.3 + ORACLE 11.2.0.3 RAC + VBOX安装文档

    ORACLE LINUX 6.3 + ORACLE 11.2.0.3 RAC + VBOX安装文档 2015-10-21 12:51 525人阅读 评论(0) 收藏 举报  分类: Oracle RA ...

  6. Oracle Database 11g Release 2(11.2.0.3.0) RAC On Redhat Linux 5.8 Using Vmware Workstation 9.0

    一,简介 二,配置虚拟机 1,创建虚拟机 (1)添加三块儿网卡:   主节点 二节点 eth0:    公网  192.168.1.20/24   NAT eth0:    公网  192.168.1 ...

  7. 【实战】静默安装-oracle 11.2.0.3 on centos 5.10

    发现网上静默安装的文章非常多,乱七八糟,五花八门!来个扫盲的!   centos 5.10 下安装oracle 11g_r2 ************************************* ...

  8. centos6.8 静默安装 oracle 11.2.0.4

    安装环境及系统要求    (下文具体参数值与路径根据自己的环境调整)操作系统:Red Hat Enterprise Linux 6 (x86) 或者CentOS 6 (x64) 数据库:Oracle ...

  9. Oracle 11.2.0.1 ADG环境MRP进程遭遇ORA-600异常终止

    环境:Linux + Oracle 11.2.0.1 ADG 现象:发现备库没有应用日志 1. 数据库查询备库目前状态 发现备库目前没有应用日志,apply lag已经显示备库有3天21小时多没有应用 ...

随机推荐

  1. golang实现mysql数据库备份

    背景 navicat是mysql可视化工具中最棒的,但是,在处理视图的导入导出方面,它是按照视图名称的字母顺序来处理的,若视图存在依赖,在导入过程中就会报错.前面已经用python写了一个,但在使用过 ...

  2. 二进制求和(LintCode)

    二进制求和 给定两个二进制字符串,返回他们的和(用二进制表示). 样例 a = 11 b = 1 返回 100 细节出了好多问题,提交了好多次... public class Solution { / ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Office Keys(思维)

    Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. 设计模式-迭代器模式(Iterator Pattern)

    本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 迭代器模式简介 迭代器相信大部分人都不陌生,java/c++等很多编程语言的容器类都支持迭代器操 ...

  5. 【计算几何】【凸包】【极角排序】【二分】Gym - 101128J - Saint John Festival

    平面上n个红点,m个黑点,问你多少个黑点至少在一个红三角形内. 对红点求凸包后,转化为询问有多少个黑点在凸包内. 点在凸多边形内部判定,选定一个凸包上的点作原点,对凸包三角剖分,将其他的点极角排序之后 ...

  6. 用Java Swing实现Freecell(空当接龙)

     目录 引言 1 游戏规则 2 界面设计和大致逻辑 2.1 界面设计 2.2 大致逻辑 3 主要功能模块设计与实现 3.1 主要思路 3.2 主要工具类 3.3 异常类 3.4 游戏初始化模块 3.5 ...

  7. 百度首席科学家 Andrew Ng谈深度学习的挑战和未来(转载)

    转载:http://www.csdn.net/article/2014-07-10/2820600 人工智能被认为是下一个互联网大事件,当下,谷歌.微软.百度等知名的高科技公司争相投入资源,占领深度学 ...

  8. JAVA EE 中之AJAX 无刷新地区下拉列表三级联动

    JSP页面 <html> <head> <meta http-equiv="Content-Type" content="text/html ...

  9. [转]Java程序员从笨鸟到菜鸟之(八十三)细谈Spring(十二)OpenSessionInView详解及用法

    首先我们来看一下什么是OpenSessionInView?    在hibernate中使用load方法时,并未把数据真正获取时就关闭了session,当我们真正想获取数据时会迫使load加载数据,而 ...

  10. 大于非负整数N的第一个回文数 Symmetric Number

    1.题目 如标题,求大于整数N(N>=0)的第一个回文数的字符串表示形式. 2.样例 1  --> 2 9  -->11 12345 -->12421 123456 --> ...