Saturday, July 31, 2010

Faster SQL performance with dbms_stats

While executing a SQL Query, the execution plan determines the best way to retrieve the data most efficiently. For Oracle, there are many way to retrieve the data from a SQL Query, like which index need to be use, order of joins to be performed and which internal join methods to be use like, hash joins, star joins, and sort merge join, etc. These execution plans are computed by the Oracle’s Cost-Based Optimizer, widely known as CBO.

The choice of executions plans made by the Oracle SQL Optimizer is only as good as the Oracle statistics. Always choose the best execution plan for a SQL query, Oracle depends on information about the tables and indexes in the query.

Using dbms_stats package, Oracle provides a simple way for the Oracle developer to collect statistics for the CBO. 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.

The old-fashioned method is Analyzing a table and using methods of dbms_utility to generating CBO statistics are obsolete and somewhat dangerous to SQL performance because they don't always capture high-quality information about tables and indexes. The CBO determines using the the object statistics to choose the best execution plan for all SQL Queries.

The dbms_stats utility does a far better job in estimating statistics, especially for large partitioned tables, and the better stats result in faster SQL execution plans.