大家都知道,子分区有两种,一种是分区为RANGE,子分区为HASH,另一种是分区为RANGE,子分区为LIST。在10g数据库中,如果在使用dbms_stats收集统计信息时,如果没有显式指定granularity(粒度),那么granularity就会取自dbms_stats配置:
而其缺省值是“AUTO”,而不再是9i下的”DEFAULT”:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> SQL> select dbms_stats.get_param('granularity') param from dual;
PARAM
------------------------------
AUTO
SQL> select dbms_stats.get_param('granularity') param from dual;
PARAM
------------------------------
AUTO
而10g自带的自动收集统计信息的任务“GATHER_STATS_JOB”,其granularity同样是取自granularity param。当然可以通过下面的SQL来更改其值:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->SQL> exec dbms_stats.set_param('granularity','global and partition');
SQL> exec dbms_stats.set_param('granularity','global and partition');
这样更改后,dbms_stats默认就会收集表以及分区级统计信息,不收集子分区级统计信息。
那么,granularity=auto时,到底是怎么样的呢?前面说到了子分区是以list方式分区时,那么就会收集子分区级统计信息,其言外之意就是如果子分区是以hash方式分区时就不会收集子分区统计信息了。到底是不是这样呢?下面做个测试,测试环境是Oracle 10.2.0.4 for Linux AS4:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> SQL> create table t1
2 partition by range(object_id)
3 subpartition by hash(data_object_id)
4 subpartitions 4
5 ( partition p1 values less than(10000),
6 partition p2 values less than(20000),
7 partition p3 values less than (maxvalue)
8 )
9 as select * from dba_objects;
Table created.
SQL> create table t2
2 partition by range(object_id)
3 subpartition by list(objec