11G新特性 -- 分区表和增量统计信息

对于分区表,优化器会在全局级别为整个表维护一份统计信息,也会在分区级别为分区表维护一份统计信息。 对于大多数分区,dml一般都是在最近的分区上执行。在11g中,数据库支持只对那些发生一定数据变化的分区收集统计信息(默认的threshold是分区的10%的行)

11g之前,数据库为了获得global统计信息,必须扫描整个表。而在11g中,数据库可以增量维护global统计信息,通过仅扫描那些有一定比例数据发生变化的分区,其他分区仍然使用老的统计信息。

分区表的增量统计信息不会增量维护直方图。

使用dbms_stat包指定分区表的分析粒度(auto、global、global and partition、all、partition、subpartition)。 如果将粒度设置为global并且将表标记为incremental的,数据库在增量的基础上收集全局统计信息。数据库也会对发生改变的分区进行自动收集统计信息。

Oracle will update the global table statistics by scanning only the partitions that have been changed instead of the entire table if the following conditions hold:
•INCREMENTAL value for the partitioned table is set to TRUE;
•PUBLISH value for the partitioned table is set to TRUE;
•User specifies AUTO_SAMPLE_SIZE for ESTIMATE_PERCENT and AUTO for GRANULARITY when gathering statistics on the table
begin
   dbms_stats.set_table_prefs(
           'SCOTT','DEPT','INCREMENTAL','TRUE');
end;
/

现在,您应该专门收集此表中粒度为 AUTO的分区 DEPT_01 上的统计信息。
begin
   dbms_stats.gather_table_stats (
           ownname         => 'SCOTT',
           tabname         => 'DEPT',
           partname        => 'DEPT_01',
           granularity     => 'AUTO'
   );
end;
原文地址:https://www.cnblogs.com/abclife/p/4727035.html