【OCP学习1Z0-053记录15】DBMS_STATS缺省参数

28.You have a range-partitioned table in your database. Each partition in the table contains the sales data for a quarter. The partition related to the current quarter is modified frequently and other partitions undergo fewer data manipulations. The preferences for the table are set to their default values. You collect statistics for the table using the following command in regular intervals:
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS('SH','SALES',GRANULARITY=>'GLOBAL');
You need statistics to be collected more quickly. What can you do to achieve this?
A. Set DYNAMIC_SAMPLING to level 4.
B. Set the STATISTICS_LEVEL parameter to BASIC. 
C. Set the INCREMENTAL value to TRUE for the partition table.
D. Increase the value of STALE_PERCENT for the partition table.
Answer: C 


参考:http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_stats.htm#ARPLS68595


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
If the INCREMENTAL value for the partitioned table was set to FALSE (default value), a full table scan is used to maintain the global statistics which is a much more resource intensive and time-consuming operation for large tables.
默认情况下INCREMENTAL 为false,如果将其设置为true,那么在搜集信息时,oracle只扫描改变的分区,这样搜集信息就会变得更快。故选C,正确
SQL> select dbms_stats.get_prefs('PUBLISH','SYS','T_PART') from dual;
DBMS_STATS.GET_PREFS('PUBLISH'
--------------------------------------------------------------------------------
TRUE
SQL> select dbms_stats.get_prefs('INCREMENTAL','SYS','T_PART') from dual;
DBMS_STATS.GET_PREFS('INCREMEN
--------------------------------------------------------------------------------
FALSE
SQL> select dbms_stats.get_prefs('GRANULARITY','SYS','T_PART') from dual;
DBMS_STATS.GET_PREFS('GRANULAR
--------------------------------------------------------------------------------
AUTO
GET_PREFS Function
This function returns the default value of the specified preference.
Syntax
DBMS_STATS.GET_PREFS (
   pname     IN   VARCHAR2,
   ownname   IN   VARCHAR2 DEFAULT NULL,
   tabname   IN   VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;
Parameters
Table 142-50 GET_PREFS Function Parameters
Parameter
Description
pname


Preference name. The default value for following preferences can be retrieved:
AUTOSTATS_TARGET
CASCADE
DEGREE
ESTIMATE_PERCENT
METHOD_OPT
NO_INVALIDATE
GRANULARITY
PUBLISH
INCREMENTAL
STALE_PERCENT
AUTOSTATS_TARGET - This preference is applicable only for auto statistics collection. The value of this parameter controls the objects considered for statistics collection. It takes the following values:
'ALL' - Statistics collected for all objects in system
'ORACLE' - Statistics collected for all Oracle owned objects
'AUTO' - Oracle decides on which objects to collect statistics
.
CASCADE - Determines whether or not index statistics are collected as part of gathering table statistics.
.
DEGREE - Determines degree of parallelism used for gathering statistics.
.
ESTIMATE_PERCENT - Determines the percentage of rows to estimate. The valid range is [0.000001,100]. Use the constant DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the appropriate sample size for good statistics. This is the default.
.
METHOD_OPT - Controls column statistics collection and histogram creation. It accepts either of the following options, or both in combination:
FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
FOR COLUMNS [size clause] column [size_clause] [,column [size_clause]...]
size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}
column is defined as column := column_name | extension name | extension
- integer : Number of histogram buckets. Must be in the range [1,254].
- REPEAT : Collects histograms only on the columns that already have histograms.
- AUTO : Oracle determines the columns on which to collect histograms based on data distribution and the workload of the columns.
- SKEWONLY : Oracle determines the columns on which to collect histograms based on the data distribution of the columns.
- column_name : name of a column
- extension : can be either a column group in the format of (column_name, colume_name [, ...]) or an expression
The default is FOR ALL COLUMNS SIZE AUTO.The default value can be changed using theSET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure andSET_TABLE_PREFS Procedure.
.
NO_INVALIDATE - The value controls the invalidation of dependent cursors of the tables for which statistics are being gathered. Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE. Use DBMS_STATS.AUTO_INVALIDATE to have Oracle decide when to invalidate dependent cursors. This is the default.
.
GRANULARITY - Determines granularity of statistics to collect (only pertinent if the table is partitioned).
'ALL' - Gathers all (subpartition, partition, and global) statistics
'AUTO'- Determines the granularity based on the partitioning type. This is the default value.
'DEFAULT' - Gathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the 'GLOBAL AND PARTITION' for this functionality. Note that the default value is now 'AUTO'.
'GLOBAL' - Gathers global statistics
'GLOBAL AND PARTITION' - Gathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object.
'PARTITION '- Gathers partition-level statistics
'SUBPARTITION' - Gathers subpartition-level statistics.
.
PUBLISH - Determines whether or not newly gathered statistics will be published once the gather job has completed. Prior to Oracle Database 11g, Release 1 (11.1), once a statistic gathering job completed the new statistics were automatically published into the dictionary tables. The user now has the ability to gather statistics but not publish them immediately. This allows the DBA to test the new statistics before publishing them.
.
INCREMENTAL - Determines whether or not the global statistics of a partitioned table will be maintained without doing a full table scan. With partitioned tables it is very common to load new data into a new partition. As new partitions are added and data loaded, the global table statistics need to be kept up to date. 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
If the INCREMENTAL value for the partitioned table was set to FALSE (default value), a full table scan is used to maintain the global statistics which is a much more resource intensive and time-consuming operation for large tables.
.
STALE_PERCENT - This value determines the percentage of rows in a table that have to change before the statistics on that table are deemed stale and should be regathered. The valid domain for stale_percent is non-negative numbers. The default value is 10%.
ownname
Owner name
tabname
Table name

dbms_stats的缺省参数保存在SYS.OPTSTAT_HIST_CONTROL$中. 
 

直接查询它就ok了.

SYS@test> select sname, sval1,spare1, spare4 from sys.OPTSTAT_HIST_CONTROL$ order by sname; 
SNAME                         |     SVAL1|    SPARE1|SPARE4 
------------------------------|----------|----------|---------------------------------------- 
APPROXIMATE_NDV               |          |         1|TRUE 
AUTOSTATS_TARGET              |          |         1|AUTO 
CASCADE                       |          |         1|DBMS_STATS.AUTO_CASCADE 
CONCURRENT                    |          |         1|OFF 
DEBUG                         |          |         1|0 
DEGREE                        |          |         1|NULL 
ENABLE_HYBRID_HISTOGRAMS      |          |         1|3 
ENABLE_TOP_FREQ_HISTOGRAMS    |          |         1|3 
ESTIMATE_PERCENT              |          |         1|DBMS_STATS.AUTO_SAMPLE_SIZE 
GATHER_AUTO                   |          |         1|AFTER_LOAD 
GLOBAL_TEMP_TABLE_STATS       |          |         1|SESSION 
GRANULARITY                   |          |         1|AUTO 
INCREMENTAL                   |          |         1|FALSE 
INCREMENTAL_INTERNAL_CONTROL  |          |         1|TRUE 
INCREMENTAL_LEVEL             |          |         1|PARTITION 
INCREMENTAL_STALENESS         |          |         1| 
JOB_OVERHEAD                  |          |         1|-1 
JOB_OVERHEAD_PERC             |          |         1|1 
METHOD_OPT                    |          |         1|FOR ALL COLUMNS SIZE AUTO 
MON_MODS_ALL_UPD_TIME         |          |          | 
NO_INVALIDATE                 |          |         1|DBMS_STATS.AUTO_INVALIDATE 
OPTIONS                       |          |         1|GATHER 
PUBLISH                       |          |         1|TRUE 
SKIP_TIME                     |          |          | 
SPD_RETENTION_WEEKS           |          |         1|53 
STALE_PERCENT                 |          |         1|10 
STATS_RETENTION               |        31|         1| 
SYS_FLAGS                     |          |          |1 
TABLE_CACHED_BLOCKS           |          |         1|1 
TRACE                         |          |         1|0

30 rows selected.

--注:STATS_RETENTION的缺省值保持在SVAL1.SPARE1=1 表示SPARE4的值是oracle的缺省参数,没有改动过.

select 'select ' a from dual 
union all 
select * from (select 'DBMS_STATS.get_prefs ('''||sname||''') '||sname||',' a  from sys.OPTSTAT_HIST_CONTROL$ order by sname) 
union all 
select '1 from dual ' from dual;

select 
DBMS_STATS.get_prefs ('APPROXIMATE_NDV') APPROXIMATE_NDV, 
DBMS_STATS.get_prefs ('AUTOSTATS_TARGET') AUTOSTATS_TARGET, 
DBMS_STATS.get_prefs ('CASCADE') CASCADE, 
DBMS_STATS.get_prefs ('CONCURRENT') CONCURRENT, 
DBMS_STATS.get_prefs ('DEBUG') DEBUG, 
DBMS_STATS.get_prefs ('DEGREE') DEGREE, 
DBMS_STATS.get_prefs ('ENABLE_HYBRID_HISTOGRAMS') ENABLE_HYBRID_HISTOGRAMS, 
DBMS_STATS.get_prefs ('ENABLE_TOP_FREQ_HISTOGRAMS') ENABLE_TOP_FREQ_HISTOGRAMS, 
DBMS_STATS.get_prefs ('ESTIMATE_PERCENT') ESTIMATE_PERCENT, 
DBMS_STATS.get_prefs ('GATHER_AUTO') GATHER_AUTO, 
DBMS_STATS.get_prefs ('GLOBAL_TEMP_TABLE_STATS') GLOBAL_TEMP_TABLE_STATS, 
DBMS_STATS.get_prefs ('GRANULARITY') GRANULARITY, 
DBMS_STATS.get_prefs ('INCREMENTAL') INCREMENTAL, 
DBMS_STATS.get_prefs ('INCREMENTAL_INTERNAL_CONTROL') INCREMENTAL_INTERNAL_CONTROL, 
DBMS_STATS.get_prefs ('INCREMENTAL_LEVEL') INCREMENTAL_LEVEL, 
DBMS_STATS.get_prefs ('INCREMENTAL_STALENESS') INCREMENTAL_STALENESS, 
DBMS_STATS.get_prefs ('JOB_OVERHEAD') JOB_OVERHEAD, 
DBMS_STATS.get_prefs ('JOB_OVERHEAD_PERC') JOB_OVERHEAD_PERC, 
DBMS_STATS.get_prefs ('METHOD_OPT') METHOD_OPT, 
DBMS_STATS.get_prefs ('MON_MODS_ALL_UPD_TIME') MON_MODS_ALL_UPD_TIME, 
DBMS_STATS.get_prefs ('NO_INVALIDATE') NO_INVALIDATE, 
DBMS_STATS.get_prefs ('OPTIONS') OPTIONS, 
DBMS_STATS.get_prefs ('PUBLISH') PUBLISH, 
DBMS_STATS.get_prefs ('SKIP_TIME') SKIP_TIME, 
DBMS_STATS.get_prefs ('SPD_RETENTION_WEEKS') SPD_RETENTION_WEEKS, 
DBMS_STATS.get_prefs ('STALE_PERCENT') STALE_PERCENT, 
DBMS_STATS.get_prefs ('STATS_RETENTION') STATS_RETENTION, 
DBMS_STATS.get_prefs ('SYS_FLAGS') SYS_FLAGS, 
DBMS_STATS.get_prefs ('TABLE_CACHED_BLOCKS') TABLE_CACHED_BLOCKS, 
DBMS_STATS.get_prefs ('TRACE') TRACE, 
1 from dual

32 rows selected.

--执行如下:

select 
DBMS_STATS.get_prefs ('APPROXIMATE_NDV') APPROXIMATE_NDV, 
DBMS_STATS.get_prefs ('AUTOSTATS_TARGET') AUTOSTATS_TARGET, 
DBMS_STATS.get_prefs ('CASCADE') CASCADE, 
DBMS_STATS.get_prefs ('CONCURRENT') CONCURRENT, 
DBMS_STATS.get_prefs ('DEBUG') DEBUG, 
DBMS_STATS.get_prefs ('DEGREE') DEGREE, 
DBMS_STATS.get_prefs ('ENABLE_HYBRID_HISTOGRAMS') ENABLE_HYBRID_HISTOGRAMS, 
DBMS_STATS.get_prefs ('ENABLE_TOP_FREQ_HISTOGRAMS') ENABLE_TOP_FREQ_HISTOGRAMS, 
DBMS_STATS.get_prefs ('ESTIMATE_PERCENT') ESTIMATE_PERCENT, 
DBMS_STATS.get_prefs ('GATHER_AUTO') GATHER_AUTO, 
DBMS_STATS.get_prefs ('GLOBAL_TEMP_TABLE_STATS') GLOBAL_TEMP_TABLE_STATS, 
DBMS_STATS.get_prefs ('GRANULARITY') GRANULARITY, 
DBMS_STATS.get_prefs ('INCREMENTAL') INCREMENTAL, 
DBMS_STATS.get_prefs ('INCREMENTAL_INTERNAL_CONTROL') INCREMENTAL_INTERNAL_CONTROL, 
DBMS_STATS.get_prefs ('INCREMENTAL_LEVEL') INCREMENTAL_LEVEL, 
DBMS_STATS.get_prefs ('INCREMENTAL_STALENESS') INCREMENTAL_STALENESS, 
DBMS_STATS.get_prefs ('JOB_OVERHEAD') JOB_OVERHEAD, 
DBMS_STATS.get_prefs ('JOB_OVERHEAD_PERC') JOB_OVERHEAD_PERC, 
DBMS_STATS.get_prefs ('METHOD_OPT') METHOD_OPT, 
DBMS_STATS.get_prefs ('MON_MODS_ALL_UPD_TIME') MON_MODS_ALL_UPD_TIME, 
DBMS_STATS.get_prefs ('NO_INVALIDATE') NO_INVALIDATE, 
DBMS_STATS.get_prefs ('OPTIONS') OPTIONS, 
DBMS_STATS.get_prefs ('PUBLISH') PUBLISH, 
DBMS_STATS.get_prefs ('SKIP_TIME') SKIP_TIME, 
DBMS_STATS.get_prefs ('SPD_RETENTION_WEEKS') SPD_RETENTION_WEEKS, 
DBMS_STATS.get_prefs ('STALE_PERCENT') STALE_PERCENT, 
DBMS_STATS.get_prefs ('STATS_RETENTION') STATS_RETENTION, 
DBMS_STATS.get_prefs ('SYS_FLAGS') SYS_FLAGS, 
DBMS_STATS.get_prefs ('TABLE_CACHED_BLOCKS') TABLE_CACHED_BLOCKS, 
DBMS_STATS.get_prefs ('TRACE') TRACE, 
1 from dual


Record View 
As of: 2014/8/11 22:01:54

APPROXIMATE_NDV:               TRUE 
AUTOSTATS_TARGET:              AUTO 
CASCADE:                       DBMS_STATS.AUTO_CASCADE 
CONCURRENT:                    OFF 
DEBUG:                         0 
DEGREE:                        NULL 
ENABLE_HYBRID_HISTOGRAMS:      3 
ENABLE_TOP_FREQ_HISTOGRAMS:    3 
ESTIMATE_PERCENT:              DBMS_STATS.AUTO_SAMPLE_SIZE 
GATHER_AUTO:                   AFTER_LOAD 
GLOBAL_TEMP_TABLE_STATS:       SESSION 
GRANULARITY:                   AUTO 
INCREMENTAL:                   FALSE 
INCREMENTAL_INTERNAL_CONTROL:  TRUE 
INCREMENTAL_LEVEL:             PARTITION 
INCREMENTAL_STALENESS:         
JOB_OVERHEAD:                  -1 
JOB_OVERHEAD_PERC:             1 
METHOD_OPT:                    FOR ALL COLUMNS SIZE AUTO 
MON_MODS_ALL_UPD_TIME:         
NO_INVALIDATE:                 DBMS_STATS.AUTO_INVALIDATE 
OPTIONS:                       GATHER 
PUBLISH:                       TRUE 
SKIP_TIME:                     
SPD_RETENTION_WEEKS:           53 
STALE_PERCENT:                 10 
STATS_RETENTION:               
SYS_FLAGS:                     1 
TABLE_CACHED_BLOCKS:           1 
TRACE:                         0 
1:                             1

猜你喜欢

转载自blog.csdn.net/viviliving/article/details/88884923