标签:
Starting with the 11g Release 1 (11.1), when gathering statistics, you have the option to automatically publish the statistics at the end of the gather operation (default behavior), or to have the new statistics saved as pending. Saving the new statistics as pending allows you to validate the new statistics and publish them only if they are satisfactory.
You can check whether or not the statistics will be automatically published as soon as they are gathered by checking the value of the PUBLISH
attribute using the DBMS_STATS
package:
Select dbms_stats.get_prefs(‘PUBLISH‘) publish from dual;
This query will return either TRUE
or FALSE
. TRUE
indicates that the statistics will be published as and when they are gathered, while FALSE
indicates that the statistics will be kept pending.
Note:
Published statistics are stored in data dictionary views, such asUSER_TAB_STATISTICS
and USER_IND_STATISTICS
. Pending statistics are stored in views such as USER_TAB_PENDING_STATS
and USER_IND_PENDING_STATS
.You can change the PUBLISH
setting at either the schema or the table level. For example, to change the PUBLISH
setting for the customers
table in the SH
schema, execute the statement:
Exec dbms_stats.set_table_prefs(‘SH‘, ‘CUSTOMERS‘, ‘PUBLISH‘, ‘false‘);
Subsequently, when you gather statistics on the customers
table, the statistics will not be automatically published when the gather job completes. Instead, the newly gathered statistics will be stored in the USER_TAB_PENDING_STATS
table.
By default, the optimizer uses the published statistics stored in the data dictionary views. If you want the optimizer to use the newly collected pending statistics, set the initialization parameter OPTIMIZER_USE_PENDING_STATISTICS
to TRUE
(the default value is FALSE
), and run a workload against the table or schema:
alter session set optimizer_use_pending_statistics = TRUE;
The optimizer will use the pending statistics instead of the published statistics when compiling SQL statements.If the pending statistics are valid, they can be made public by executing the following statement:
Exec dbms_stats.publish_pending_stats(null, null);
You can also publish the pending statistics for a specific database object. For example, by using the following statement:
Exec dbms_stats.publish_pending_stats(‘SH‘,‘CUSTOMERS‘);
If you do not want to publish the pending statistics, delete them by executing the following statement:
Exec dbms_stats.delete_pending_stats(‘SH‘,‘CUSTOMERS‘);
You can export pending statistics using dbms_stats.export_pending_stats
function. Exporting pending statistics to a test system enables you to run a full workload against the new statistics.
http://docs.oracle.com/cd/B28359_01/server.111/b28274/stats.htm#BEIEGBGI
标签:
原文地址:http://www.cnblogs.com/seasonzone/p/4942648.html