dbms_stats.get_prefs: It will get you the default values of various preferences.
select dbms_stats.get_prefs('stale_percent','APP_OWNER','MY_CUSTOMER') stale_percent from dual;
PL/SQL procedure successfully completed.
set_global_pref: Let you set global statistics preferences for various parameters. You need the sysdba to use this procedure.
exec dbms_stats.set_global_prefs('estimate_percent','10');
PL/SQL procedure successfully completed.
delete_table_prefs: Delete statistics preferences of the specified table
SQL> exec dbms_stats.delete_table_prefs('APP_OWNER','TR_CUSTOMER','DEGREE');
PL/SQL procedure successfully completed.
delete_schema_prefs: Delete statistics preferences for a specific schema
SQL> exec dbms_stats.delete_schema_prefs('JOHN_DEV,'CASCADE');
PL/SQL procedure successfully completed.
delete_database_prefs: Delete statistics preferences for all tables in the database
Export / Import Statistics Prefrence:
· export_table_prefs / import_table_prefs
· export_schema_prefs / import_schema_prefs
· exprt_database_prefs / import_database_prefs
Pending (Private Statistics) v.s Publishing Statistics Immediately
In prior database version, statistics was always ready for use by the cost optimizer. The pushing of the statistics was automatic. In 11g, you can now not to publish the statistics, hence giving you tan opportunity to test the new statistics for actual improve the SQL performance.
SQL> select dbms_stats.get_prefs('publish') from dual;
DBMS_STATS.GET_PREFS('PUBLISH')
----------------------------------------------------
TRUE
Pending statistics is also called Private Statistics. It’s not published unless you pushing it by running the publish_pending_stats procedure in the DBMS_STATS package. If the query performance is not gained, you can delete the pending statistics by running the delete_pending_stats procedure.
Example:
SQL> exec dbms_stats.set_table_prefs('APP_OWNER','PRODUCTS','publish','false');
PL/SQL procedure successfully completed.
select dbms_stats.get_prefs('publish','APP_OWNER','PRODUCTS') from dual;
DBMS_STATS.GET_PREFS('PUBLISH','APP_OWNER','PRODUCTS')
------------------------------------------------------------------------------------------
FALSE
Gather Private Statistics
SQL> exec dbms_stats.delete_table_stats('APP_OWNER','PRODUCTS');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats('APP_OWNER','PRODUCTS');
PL/SQL procedure successfully completed.
select table_name, last_analyzed, num_rows
from dba_tables
where table_name = 'PRODUCTS';
TABLE_NAME LAST_ANALYZED NUM_ROWS
------------------------------ ----------------- ------------
PRODUCTS ========================è not publish yet..
select table_name, last_analyzed, num_rows
from dba_tab_pending_stats
where table_name = 'PRODUCTS';
TABLE_NAME LAST_ANALYZED NUM_ROWS
------------------------------ ----------------- ------------
PRODUCTS 20110130 17:17:35 49780
The dba_tab_pending_stats / user_tab_pending_stats show pending statistics for tables, partitions, and subpatitions.
Publish Stats
SQL> exec dbms_stats.publish_pending_stats('APP_OWNER', 'PRODUCTS');
PL/SQL procedure successfully completed.
SQL> select table_name, last_analyzed, num_rows from dba_tables where table_name = 'PRODUCTS';
TABLE_NAME LAST_ANALYZED NUM_ROWS
------------------------------ ----------------- ------------
PRODUCTS 20110130 17:17:35 49780
1 row selected.
SQL> select table_name, last_analyzed, num_rows from dba_tab_pending_stats where table_name = 'PRODUCTS';
no rows selected
Delete Pending Stats: if the query doesn’t gain performance, you can always delete the pending stats
SQL> exec dbms_stats.delete_pending_stats('APP_OWNER','PRODUCTS');
PL/SQL procedure successfully completed.
Pulish Pending Stats for a schema:
SQL> exec dbms_stats.publish_pending_stats('ETL_APP', null);
Publish all pending statistics in the database:
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.publish_pending_stats(null,null);