The SQL Optimizer
Oracle Tips by Burleson Consulting
In a perfect world, the SQL optimizer should
be able to generate the most efficient method to service the data
request. If the SQL optimizer has all of the information about all
of the tables involved in the query (e.g., the number of rows, the
distribution of values within a column), the optimizer should always
choose the best execution plan for accessing the data.
In the real world, the SQL optimizer requires
human assistance. It is the responsibility of the Oracle Remote DBA to
ensure that all of the object statistics are available to the SQL
optimizer, and the overwhelming complexity of SQL optimization makes
it very difficult for any vendor to deliver an optimizer that always
chooses the best access path to the data. Hence, we need a book such
as this to understand how to help the optimizer choose the most
efficient path to the data.
The Goals of SQL Tuning
SQL tuning is the most time-consuming and
challenging of all Oracle tuning activities. Unlike SGA tuning,
which is performed only once, SQL tuning is an ongoing process. Each
SQL statement must be individually tuned, and the tuning must be
made permanent by using hints or with the new Oracle8i optimizer
plan stability feature. For details on using optimizer plan
stability, please see Chapter 13.
Also, SQL tuning has the most immediate
positive impact on Oracle performance. When the Oracle optimizer
chooses a less-than-optimal execution plan, human tuning can often
triple the speed of the query. For queries that are executed
thousands of time per day, this can result in a dramatic improvement
of database throughput and extend the life of the hardware on the
database server. The following list summarizes the goals of SQL
- To ensure that all SQL has been
“approved” for performance It is important to note that
the goals of the programmers who write the SQL are very different
from the goals of the person charged with tuning the SQL. The
programmers are concerned with getting a query with the correct
result as quickly as possible, and it is not uncommon to
find SQL that is less than optimal from a performance perspective.
- To create Oracle statistics and indexes
that will benefit all SQL The Oracle SQL optimizer does not
exist in a vacuum, and it is the goal of the Oracle Remote DBA to create
appropriate indexes and object analysis techniques to ensure that
all SQL will perform in an optimal fashion.
- To lock down the execution plan for all
SQL Adding a new index can sometimes result in a change to
dozens of SQL statements, and a primary goal of SQL tuning is to
make the tuning changes permanent. For any SQL statement, there is
only one optimal execution plan, and once that is identified, it
is the goal of the Oracle Remote DBA to make the execution plan permanent
by adding hints to the query or by using optimizer plan stability.
We will be discussing these goals as a
central theme throughout the body of this book.
This is an excerpt from "Oracle High-Performance SQL Tuning" by
Donald K. Burleson, published by Oracle Press.