- 最后登录
- 2015-9-21
- 在线时间
- 15 小时
- 威望
- 0
- 金钱
- 109
- 注册时间
- 2013-5-27
- 阅读权限
- 10
- 帖子
- 53
- 精华
- 0
- 积分
- 0
- UID
- 1109
|
1#
发表于 2013-8-16 16:02:17
|
查看: 6599 |
回复: 8
刘大:
关于表的统计信息收集和直方图有些疑惑
下面是我以前的测试过程
请教问题为: 使用"columns size 2 DEPTNO"仅收集指定字段的直方图与
"for all columns size 1 FOR COLUMNS SIZE 2 DEPTNO JOB"收集直方图以及其他字段的基本信息有何区别,应如何取舍
=======================================
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP',cascade=>TRUE,no_invalidate=>FALSE);
PL/SQL procedure successfully completed
SQL> select t.column_name,t.num_buckets,t.last_analyzed from dba_tab_col_statistics t where t.table_name = 'EMP' and owner='SCOTT';
COLUMN_NAME NUM_BUCKETS LAST_ANALYZED
------------------------------ ----------- -------------
EMPNO 1 2012-11-2 2:5
ENAME 1 2012-11-2 2:5
JOB 5 2012-11-2 2:5
MGR 1 2012-11-2 2:5
HIREDATE 1 2012-11-2 2:5
SAL 1 2012-11-2 2:5
COMM 1 2012-11-2 2:5
DEPTNO 3 2012-11-2 2:5
8 rows selected
SQL> select t.NUM_ROWS,t.last_analyzed from dba_tables t where t.table_name = 'EMP' and owner='SCOTT';
NUM_ROWS LAST_ANALYZED
---------- -------------
14 2012-11-2 3:0
不带任何参数即为AUTO,由系统自动指定直方图的桶数目
SQL> exec dbms_stats.delete_table_stats(ownname=>'SCOTT',tabname=>'EMP')
PL/SQL procedure successfully completed
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP',cascade=>TRUE,no_invalidate=>FALSE,method_opt => 'for all columns size 1',estimate_percent=>20);
PL/SQL procedure successfully completed
SQL> select t.column_name,t.num_buckets,t.last_analyzed from dba_tab_col_statistics t where t.table_name = 'EMP' and owner='SCOTT';
COLUMN_NAME NUM_BUCKETS LAST_ANALYZED
------------------------------ ----------- -------------
EMPNO 1 2012-11-2 2:5
ENAME 1 2012-11-2 2:5
JOB 1 2012-11-2 2:5
MGR 1 2012-11-2 2:5
HIREDATE 1 2012-11-2 2:5
SAL 1 2012-11-2 2:5
COMM 1 2012-11-2 2:5
DEPTNO 1 2012-11-2 2:5
8 rows selected
SQL> select t.NUM_ROWS,t.last_analyzed from dba_tables t where t.table_name = 'EMP' and owner='SCOTT';
NUM_ROWS LAST_ANALYZED
---------- -------------
14 2012-11-2 2:5
以上指定的所有字段均不收集直方图,只收集表的统计信息
下面两种写法均只收集指定字段的直方图,其他字段不收集任何信息
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP',cascade=>TRUE,no_invalidate=>FALSE,method_opt => 'for columns size 1 DEPTNO SIZE 2 ',estimate_percent=>20);
PL/SQL procedure successfully completed
SQL> select t.NUM_ROWS,t.last_analyzed from dba_tables t where t.table_name = 'EMP' and owner='SCOTT';
NUM_ROWS LAST_ANALYZED
---------- -------------
14 2012-11-2 3:0
SQL> select t.column_name,t.num_buckets,t.last_analyzed from dba_tab_col_statistics t where t.table_name = 'EMP' and owner='SCOTT';
COLUMN_NAME NUM_BUCKETS LAST_ANALYZED
------------------------------ ----------- -------------
DEPTNO 2 2012-11-2 3:0
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP',cascade=>TRUE,no_invalidate=>FALSE,method_opt => 'for columns size 2 DEPTNO ',estimate_percent=>20);
PL/SQL procedure successfully completed
SQL> select t.column_name,t.num_buckets,t.last_analyzed from dba_tab_col_statistics t where t.table_name = 'EMP' and owner='SCOTT';
COLUMN_NAME NUM_BUCKETS LAST_ANALYZED
------------------------------ ----------- -------------
DEPTNO 2 2012-11-2 3:0
下面的写法才能正确实现需求:
SQL> exec dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'EMP',cascade=>TRUE,no_invalidate=>FALSE,method_opt => 'for all columns size 1 FOR COLUMNS SIZE 2 DEPTNO JOB',estimate_percent=>20);
PL/SQL procedure successfully completed
SQL> select t.NUM_ROWS,t.last_analyzed from dba_tables t where t.table_name = 'EMP' and owner='SCOTT';
NUM_ROWS LAST_ANALYZED
---------- -------------
14 2012-11-2 3:0
SQL> select t.column_name,t.num_buckets,t.last_analyzed from dba_tab_col_statistics t where t.table_name = 'EMP' and owner='SCOTT';
COLUMN_NAME NUM_BUCKETS LAST_ANALYZED
------------------------------ ----------- ------------------------------
EMPNO 1 2012-11-2 3:06:58
ENAME 1 2012-11-2 3:06:58
JOB 2 2012-11-2 3:06:58
MGR 1 2012-11-2 3:06:58
HIREDATE 1 2012-11-2 3:06:58
SAL 1 2012-11-2 3:06:58
COMM 1 2012-11-2 3:06:58
DEPTNO 2 2012-11-2 3:06:58
8 rows selected |
|