设为首页 加入收藏

TOP

在Oracle11.2.0.1.0下dbms_stats.gather_table_stats收集直方图不准(一)
2015-07-24 11:26:46 来源: 作者: 【 】 浏览:11
Tags:Oracle11.2.0.1.0 dbms_stats.gather_table_stats 收集 方图 不准
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
---------- ---------- --------
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORA-01555错误总结(二) 下一篇oracle查看当前的数据库实例名称..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)
·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)