Beruflich Dokumente
Kultur Dokumente
Document 372431.1
Type: BULLETIN
In this Document
Purpose
Scope
Details
References
APPLIES TO:
Oracle Database - Enterprise Edition - Version 6.0.0.0 to 11.1.0.7 [Release 6.0 to 11.1]
Information in this document applies to any platform.
***Checked for relevance on 25-Aug-2013***
PURPOSE
This article Provides information regarding how to tune a newly written query.
SCOPE
Aimed at Oracle Support Analysts, DBA's and Application Developers
DETAILS
A new query that performs badly is typified by a lack of historical information that may provide guidance as to how
to encourage it to perform more acceptably.
There is likely to be no known 'good' access path.
If there is a known 'good' access path then please see:
Note.179668.1 * TROUBLESHOOTING: Tuning Slow Running Queries
Note that these steps also apply equally to cases where a query performs badly and used to perform well but only
the current plan is available, or for any case where no 'target' plan is available for the query.
1. Use the SQL Tuning Advisor
Since there is no known target access path, a good strategy is to use the SQL Tuning Advisor to suggest
some suitable modifications. See:
Oracle Database Performance Tuning Guide
10g Release 2 (10.2)
Part Number B14211-03
Chapter 12 Automatic SQL Tuning
12.2 SQL Tuning Advisor
Note:271196.1 Automatic SQL Tuning - SQL Profiles.
1/4
6/24/2014
Document 372431.1
If you are unable to use the advisor, then the manual steps that you need to perform are outlined
below. Please note that query tuning, by its very nature is an advanced activity and often requires a
complete understanding of the environment where the database resides.
2/4
6/24/2014
Document 372431.1
with row sources that return small numbers of rows or which eliminate significant amounts of data is often
central to obtaining an acceptable plan.
Construct a join order graph for the query.
A join graph illustrates which tables are joined to each other in a query. Drawing a join graph is especially
useful when there are large numbers of tables in a query as presenting just the join information makes it
clear which joins are available based on the supplied join predicates. To construct a join graph, examine the
where clause of the query and identify the join predicated. Each table involved in a join is written down and
a line is drawn between them to indicate a join. Examining each join predicate produces a 'matrix' like join
graph.
Consider the following query:
SELECT dname
FROM emp, dept, bigemp
WHERE emp.deptno = dept.deptno
AND emp.empno = bigemp.empno
This query has a join between emp and dept and a join between emp and bigemp.
The join graph for this would be:bigemp -- emp -- dept.
The join graph for a query helps the analyst to visualise alternative join orders and start points that could be
used for a query. It also helps identify join orders that may not be advisable and Cartesian Products (i.e.
where a join may be missing).
In the example above forcing a join order of bigemp -- dept -- emp may be inadvisable as trying to join
bigemp to dept would result in a cartesian product (there is no join predicate that joins bigemp to dept in the
query).
N.B cartesian products are not necessarily a bad thing. With low data volumes (and especially where one of
the row sources contains 1 row) they can provide good performance.
Choose a join order and force it using the ORDERED hint.
Often there are many different options here. Combining table specific predicate and cardinality information
gathered earlier with the join order information can identify a sensible driving point for the query. Initially,
choose a join order that eliminates as many rows as possible early in the query execution plan (e.g. try
placing an object with very few rows at the start of the join order. Hopefully this will eliminate a significant
proportion of whatever row source it is joined to). If this does not give an acceptable plan then try different
join orders.
Be careful of related objects
Bear in mind that certain objects may perform more efficiently if they follow other related objects. For
example, a query based upon object whose rows are eliminated based on a join predicate may perform
better if the object that it joins to is accessed before it so that the join values are present when that object is
accessed. Also, different, more efficient, access methods may be opened by changing the join order (e.g. a
partitioned table where partitions are pruned based on a join predicate would usually need to follow the
driving row source in a nested loop join in order for partition elimination to occur.
See the Does the join order allow index usage?section in
Note:67522.1 * Diagnosing Why a Query is Not Using an Index
for more information on this process.
Consider more advanced techniques.
Refer to RELATED DOCUMENTS below.
In particular, see:
Note:163563.1 * TROUBLESHOOTING: Advanced Query Tuning
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=155z6b9yjo_513&id=372431.1
3/4
6/24/2014
Document 372431.1
REFERENCES
NOTE:122812.1 - * TROUBLESHOOTING: Tuning Queries That Cannot be Modified (10g and below)
NOTE:163563.1 - * TROUBLESHOOTING: Advanced Query Tuning
NOTE:179668.1 - TROUBLESHOOTING: Tuning Slow Running Queries
NOTE:207434.1 - Tuning Queries: 'Quick and Dirty' Solutions
NOTE:214106.1 - Using TKProf to compare actual and predicted row counts
NOTE:233112.1 - START HERE> Diagnosing Query Tuning Problems
NOTE:271196.1 - Automatic SQL Tuning - SQL Profiles
NOTE:388474.1 - * How to Gather Optimizer Statistics on 9i
NOTE:44961.1 - Statistics Gathering: Frequency and Strategy Guidelines
NOTE:452011.1 - * Restoring Table Statistics (Oracle 10G Onwards)
NOTE:605439.1 - * How to Gather Optimizer Statistics on 10g
NOTE:67522.1 - * Diagnosing Why a Query is Not Using an Index
NOTE:742112.1 - Troubleshooting Query Performance Degradation - Recommended Actions
NOTE:749227.1 - * How to Gather Optimizer Statistics on 11g
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=155z6b9yjo_513&id=372431.1
4/4