Dbms Stats
Dbms Stats
Mohamed Fowjil
DBMS_STATS
• Oracle Corporation strongly recommends to use the
DBMS_STATS package rather than ANALYZE for most
statistics collection.
• That package collect statistics in parallel, collect global
statistics for partitioned objects, and fine tune your statistics
collection in other ways. Further, the cost-based optimizer will
eventually use only statistics that have been collected by
DBMS_STATS
DBMS_STATS
Procedures
• The DBMS_STATS package contains over 40 procedures.
These include procedures to: delete existing statistics for a
table, schema, or database; set statistics to desired values;
export and import statistics; gather statistics for a schema or
entire database; and monitor tables for changes.
• The old fashioned “analyze table” and dbms_utility methods
for generating CBO statistics are obsolete and somewhat
dangerous to SQL performance.
• This is because the cost-based SQL Optimizer (CBO) relies on
the quality of the statistics to choose the best execution plan
for all SQL statements.
• The dbms_stats utility does a far better job in estimating
statistics, especially for large partitioned tables, and the better
stats results in faster SQL execution plans.
Gathering Statistics with
DBMS_STATS Procedures
• Statistics are gathered using the DBMS_STATS package. This
PL/SQL package is also used to modify, view, export, import, and
delete statistics.
• The DBMS_STATS package can gather statistics on table and
indexes, and well as individual columns and partitions of tables.
• The DBMS_STATS package can gather statistics on table and
indexes, and well as individual columns and partitions of tables.
• When statistics are updated for a database object, Oracle
invalidates any currently parsed SQL statements that access the
object. The next time such a statement executes, the statement is
re-parsed and the optimizer automatically chooses a new
execution plan based on the new statistics.
• Oracle Corporation recommend setting the
ESTIMATE_PERCENT parameter of the gathering procedures
to DBMS_STATS.AUTO_SAMPLE_SIZE. This will
maximize performance gains while achieving good statistical
accuracy.