Академический Документы
Профессиональный Документы
Культура Документы
Using TKProf to compare actual and predicted row counts [ID 214106.1]
Applies to:
Purpose
Explain how TKProf can be used to highlight differences in predicated and actual row counts to identify potential optimizer problems.
SQL_TRACE combined with TKProf can provide some very useful information to assist with the tuning of queries when compared against Explain plan output.
Especially useful for tuning SQL are the actual row counts as these can be compared against the optimizer's predicted row counts. Expected row counts (cardinalities e.g. Card=12345) can
optimized using the Cost Based Optimizer (CBO). Actual row counts can be found in tkprof output or in the STAT lines from raw <> (or <> output ). Any anomalies can then be investigated.
For example, if the actual number of rows returned by a particular explain plan step differs significantly from the CBO's cardinality estimates, then it is possible that this is a source of a bad p
incorrect statistics can be investigated and corrected.
The execution plan from autotrace (containing cost and cardinality information) can be compared with the actual row counts displayed against the raw trace file or the tkprof explain plan:
Autotrace output:
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=14 Bytes=126)
1 0 HASH JOIN (Cost=5 Card=14 Bytes=126)
2 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=14 Bytes=98)
3 1 TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=4 Bytes=8)
The autotrace output shows the expected cardinality figures (Card=...) for each step in the query. These values are calculated using the statistics gathered on the objects with modifications a
The cardinalities can be compared with the actual figures as collected by SQL_TRACE:
The cnt value in the relevant 'STAT' line for the query shows the row count for each step of the recorded plan (the number immediately after the STAT # indicates the cursor that the statistic
TKProf to give the following output:
The cardinality and row figures for each step should be the same. If they are not then this may indicate thats there is a problem in the way the base statistics have been gathered (no data sa
skewed data etc) or some deficiency in the cardinality computation method.
The Cost Based optimizer has a few limitations to its model that affects queries in a small number of cases. These limitations are documented in the following article:
References
Related
Products
z Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=214106.1 11/7/2010
Page 2 of 2
Keywords
AUTOTRACE; SQL_TRACE
Back to top
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=214106.1 11/7/2010