Sie sind auf Seite 1von 18

<Insert Picture Here> Optimizer Wrong Results

Dena Feinblat
Global Customer Services, EMEA Database Performance
Wrong Results

Wrong results issues are important since they can easily destroy confidence in
everything else however unrelated.
Customers cannot afford to return wrong results especially in financial situations.
The uncertainty of results is often as bad as actual wrong results.
Wrong results may be a result of how the optimizer puts the execution plan
together.
Example of Optimizer Wrong Results are: Missing Predicates or wrongly derived
predicates, Invalid Transformations
Sometimes the reason is not related to the optimizer. The wrong results maybe
related to different NLS settings, XDB , corruption (usually logical)
This presentation only deals with Wrong Results related to the optimizer
What is the nature of Wrong Results ?

• Wrong number of rows


• No rows, less rows , more

• Wrong Column Values for one or more columns

• Has this query ever given the correct results?


• If this has not ever given correct results then how do they know that this
result is incorrect?
• Identifying where good results occurred is a good way of finding potential
workarounds to the problem.
Identifying What has Changed
• Different versions
• Often a change in optimizer version can cause wrong results as different
features cause different plans to be considered.
• Wrong Results may occur in a new version as a result of code changes
in the new version or a result of code changes in bug fix

• Different databases
• Different optimizer statistics or different environment/optimizer
parameters can result in wrong results being encountered

• Change in same database


• Data volume and different optimizer statistics causing a different plan
• Change in data volume ,indexes added, some kind of corruption
Frequency of the Wrong Results

Consistently
Occurs consistently for all users

• Intermittently
• Certain users always get good results and others wrong results
• Does same session get intermittently wrong and correct results
• Is there a pattern ?
Information to Gather

• Wrong Results Issues - Recommended Actions (Doc ID 150895.1)

It is vital to gather diagnostics that illustrate the query returning both the
correct and the wrong results

• Query Text
• Run-time Traces (10046 trace)
• Execution Plans and Optimizer Information (Explain Plan ,10053 trace)
• Workarounds and Environment
Run Time Traces

• 10046 trace with binds and waits (i.e. 10046 trace level 12)
• Recommended Method for Obtaining 10046 trace for Tuning (Doc ID 376442.1)

• Run time traces provide information about what actually happens when the query is
run.

• If rows are missing or added, it may be possible to spot this in the row source trace
and attribute this to a particular operation.

• Additionally comparing the run time trace with the optimizer estimate (explain plan)
*may* indicate implementation difficulties
Run Time Trace - Example
• Correct Results
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.27 0.31 0 0 0 0
Execute 1 0.01 0.00 0 0 0 0
Fetch 128 3.43 16.59 9198 10174 0 1893
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 130 3.71 16.90 9198 10174 0 1893

Misses in library cache during parse: 1


Optimizer mode: ALL_ROWS
Parsing user id: SYS

Rows Row Source Operation


------- ---------------------------------------------------
1893 FILTER (cr=10213 pr=9201 pw=1484 time=16569281 us)
10351 HASH GROUP BY (cr=10213 pr=9201 pw=1484 time=16561030 us)
121846 HASH JOIN (cr=10204 pr=8613 pw=896 time=15047012 us)
10351 TABLE ACCESS BY INDEX ROWID PS_JOB (cr=5905 pr=3500 pw=0 time=12410225 us)
10351 INDEX RANGE SCAN PS2JOB (cr=73 pr=73 pw=0 time=140639 us)(object id 12125728)
880553 INDEX FAST FULL SCAN PSDJOB (cr=4269 pr=4214 pw=0 time=900582 us)(object id 2523881)
Run Time Trace - Example
• Wrong Results
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.02 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.88 0.87 0 4342 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 3 0.89 0.89 0 4342 0 0

Misses in library cache during parse: 1


Optimizer mode: ALL_ROWS
Parsing user id: SYS

Rows Row Source Operation


------- ---------------------------------------------------
0 HASH JOIN (cr=4342 pr=0 pw=0 time=870594 us)
10351 VIEW index$_join$_001 (cr=4342 pr=0 pw=0 time=855422 us)
10351 HASH JOIN (cr=4342 pr=0 pw=0 time=855419 us)
10351 INDEX RANGE SCAN PS2JOB (cr=73 pr=0 pw=0 time=71 us)(object id 12125728)
880553 INDEX FAST FULL SCAN PSDJOB (cr=4269 pr=0 pw=0 time=120 us)(object id 2523881)
0 VIEW VW_SQ_1 (cr=0 pr=0 pw=0 time=0 us)
0 HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
0 INDEX FAST FULL SCAN PSDJOB (cr=0 pr=0 pw=0 time=0 us)(object id 2523881)
Execution Plans
• Note:235530.1 Recommended Method for Obtaining a Formatted Explain Plan
• 10053 Trace - Optimizer information
• Note: 225598.1 How to Obtain Tracing of Optimizer Computations (EVENT 10053)

• Execution plans shows the access path that the optimizer has decided upon in
order to optimizer the query performance.
• If an invalid access paths is produced, predicates are missing or wrongly derived
or invalid transformations have occurred, then by comparing the access paths
for correct and incorrect cases a pattern or reason may be spotted.
• Check the execution plan for any kind of transformations or syntax that may be a
“different”
• Examples: "hash group by", VW_GBF_1 (group by placement) , ANSI query, function-
based index
• Check for constructs in predicate information that may look problematic
• Example: Null is not null
Execution Plan - Example
• Wrong Results
Bug 5462687: CHECK CONSTRAINT CAUSES WRONG RESULTS TO OCCUR

sqlplus scott/tiger

select * from cash_payment_hdr where cshpay_hdr_flag=9;

Above query would give no rows.


----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 65 | 0 (0)|
|* 1 | FILTER | | | | |
|* 2 | TABLE ACCESS FULL| CASH_PAYMENT_HDR | 680 | 44200 | 5 (0)|
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------
1 - filter(NULL IS NOT NULL)
2 - filter("CSHPAY_HDR_FLAG"=9)
• Workarounds and Environment

• The Workaround may help to identify where the problem is.


Example: If an index is avoided, then that may point to a problem with the index
data or the way in which it is retrieved.

• Do not however jump to an “obvious” conclusion as there may be more to it than


that.

• If a potential issue has been identified, then there may be parameters or patches
that resolve the issue.
In-House Testing
• It is often easier and faster to solve wrong results by getting a testcase (including
data) in order to reproduce, test and diagnose in-house

• In this way certain workarounds and patch fixes can be tested without having to
involve customer with unnecessary “ping-ponging” and needless guessing
• Testcase should include
• pfile/spfile information
• Export dump file including data (or any other way to reproduce data)
• DDL for views and functions (sometimes errors received from export)
• Optimizer Statistics
Transferring Optimizer Statistics to Support (Doc ID 242489.1)

• How to Submit a Testcase to Oracle Support for Reproducing an Execution Plan


(Doc Id 390610.1)
• How to create a sql testcase using the dbms_sqldiag package (Doc ID 727863.1)
• SQLT can help setup a testcase excluding data that can be imported afterwards
Filing a Bug

• If the problem seems to be an unknown, then a bug should be


filed
• It is essential for opening a bug that you have a testcase
including data that reproduces the issue.
• Development cannot diagnose wrong results without a
reproducible testcase
Workarounds
As a solution may not be immediate, a temporary workaround/solution
may need to be found for customer
• Optimizer Parameters /Hints
These can include setting optimizer_features_enable = <lower version
level>, or any other optimizer parameter that results in correct results
(optimizer_mode, _optimzier_cost_based_transformation ...)
• Repair Advisor
In 11g the SQL repair advisor can be used to detect ,assist with the
causes of wrong results as well as "patch" the query
Note:466604.1 How to use DBMS_SQLDIAG to diagnose Wrong Results
Issues
Workarounds – 10053 Optimizer Hint
SELECT
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('10.2.0.5')
OPT_PARAM('query_rewrite_enabled' 'false')
ALL_ROWS
OUTLINE(@"SEL$C772B8D1")
UNNEST(@"SEL$2")
OUTLINE(@"SEL$7511BFD2")
OUTLINE(@"SEL$1")
INDEX_JOIN(@"SEL$C772B8D1" "A"@"SEL$1" "PS2JOB" ("PS_JOB"."EMPLID" "PS_JOB"."HR_STATUS" "PS_JOB"."EFFDT" "PS_JOB"."EFFSEQ“
PS_JOB"."EMPL_RCD"))
NO_ACCESS(@"SEL$C772B8D1" "VW_SQ_1"@"SEL$7511BFD2")
LEADING(@"SEL$C772B8D1" "A"@"SEL$1" "VW_SQ_1"@"SEL$7511BFD2")
USE_HASH(@"SEL$C772B8D1" "VW_SQ_1"@"SEL$7511BFD2")
INDEX_FFS(@"SEL$683B0107" "AA"@"SEL$2" ("PS_JOB"."EMPLID" "PS_JOB"."HR_STATUS" "PS_JOB"."EFFDT" "PS_JOB"."EFFSEQ"
"PS_JOB"."EMPL_RCD"))
USE_HASH_AGGREGATION(@"SEL$683B0107")
END_OUTLINE_DATA
*/
FROM ps_job a
WHERE a.effdt = (SELECT MAX (aa.effdt)
FROM ps_job aa WHERE aa.emplid = a.emplid AND aa.empl_rcd = 0)
AND a.empl_rcd = 0 AND a.jobcode = '004302’
Useful Tools and Notes
• Search for existing bugs
• Try to narrow down the possible causes and search for potential bugs
using the following notes:
• Note 150895.1: Wrong Results Issues - Recommended
• Note 174244.1 Handling Wrong Results Issues (Internal)

• Search Orion for bugs using tag “wrongres” as follows:


• myKM BugTag List :
http://mykm-prod.oraclecorp.com/pls/apex/f?p=999:1400:5831511986250735
• Orion Alt(ernate) Search
• Use Event 10060
• If the query can be modified or hinted so that the results are affected, then it is
often useful to compare the output of Event 10060 and look for additional or
missing predicates.
• The output of this event can also be useful even if there is nothing to compare
against in as much as spurious or obviously missing predicates may be spotted.
Useful Notes

• Wrong Results Issues - Recommended Actions (Doc ID 150895.1)


• Handling Wrong Results Issues (Doc ID 468072.1)
• Handling Wrong Results Issues (Internal) (Doc ID 174244.1)
• How to Diagnose Wrong Result Issues (Doc ID 377500.1)

Das könnte Ihnen auch gefallen