| Handling and resolving unshared cursors/large version_counts [ID 296377.1] | |||||
|
| |||||
| 修改时间 10-AUG-2009 类型 TROUBLESHOOTING 状态 PUBLISHED | |||||
In this Document
Purpose
Last Review Date
Instructions for the Reader
Troubleshooting Details
References
We can now see the 2nd child ( 0000000386A91AA0) and also the reasons why it could not be shared with the first (The 'Y's denote a mismatch) The reasons are (1) AUTH_CHECK_MISMATCH and (2) TRANSLATION_MISMATCH This is basically because the objects under my new user do not map to those of SCOTT (the current child). So , authentication fails because I cannot access SCOTTs objects and translation fails because we have different object_ids.
[top]
3. What do the reasons given in v$SQL_SHARED_CURSOR mean?
Below are the list of reasons given as well as some workable examples (Those denoted by ** are the ones most often seen) :-
1. UNBOUND_CURSOR - The existing child cursor was not fully built (in other words, it was not optimized)
2. SQL_TYPE_MISMATCH - The SQL type does not match the existing child cursor
3. **OPTIMIZER_MISMATCH - The optimizer environment does not match the existing child cursor
select count(*) from emp; ->> 1 PARENT, 1 CHILD
alter session set optimizer_mode=ALL_ROWS
select count(*) from emp; ->> 1 PARENT, 2 CHILDREN (The optimizer mode has changed and therefore the existing child cannot be reused)
(The same applies with events - if I turned on tracing with 10046 than I would get the OPTIMIZER_MISMATCH again and a 3rd child)
OUTLINE_MISMATCH - The outlines do not match the existing child cursor
If my user had created stored outlines previously for this command and they were stored in seperate categories (say "OUTLINES1" and "OUTLINES2") running:-
--> Would create a 2nd child as the outline used is different than the first run.
STATS_ROW_MISMATCH - The existing statistics do not match the existing child cursor
Check that 10046/sql_trace is not set on all sessions as this can cause this.
LITERAL_MISMATCH - Non-data literal values do not match the existing child cursor
SEC_DEPTH_MISMATCH - Security level does not match the existing child cursor
EXPLAIN_PLAN_CURSOR - The child cursor is an explain plan cursor and should not be shared
Explain plan statements will generate a new child by default - the mismatch will be this.
BUFFERED_DML_MISMATCH - Buffered DML does not match the existing child cursor
PDML_ENV_MISMATCH - PDML environment does not match the existing child cursor
INST_DRTLD_MISMATCH - Insert direct load does not match the existing child cursor
SLAVE_QC_MISMATCH -The existing child cursor is a slave cursor and the new one was issued by the coordinator
(or, the existing child cursor was issued by the coordinator and the new one is a slave cursor).
TYPECHECK_MISMATCH - The existing child cursor is not fully optimized
AUTH_CHECK_MISMATCH - Authorization/translation check failed for the existing child cursor
The user does not have permission to access the object in any previous version of the cursor. A typical example would be where each user has it's own copy of a table
**BIND_MISMATCH - The bind metadata does not match the existing child cursor
variable a varchar2(100);
select count(*) from emp where ename = :a ->> 1 PARENT, 1 CHILD
variable a varchar2(400);
select count(*) from emp where ename = :a ->> 1 PARENT, 2 CHILDREN (The bind 'a' has now changed in definition)
DESCRIBE_MISMATCH - The typecheck heap is not present during the describe for the child cursor
LANGUAGE_MISMATCH - The language handle does not match the existing child cursor
TRANSLATION_MISMATCH - The base objects of the existing child cursor do not match
The definition of the object does not match any current version. Usually this is indicative of the same issue as "AUTH_CHECK_MISMATCH" where the object is different anyway
ROW_LEVEL_SEC_MISMATCH - The row level security policies do not match
INSUFF_PRIVS - Insufficient privileges on objects referenced by the existing child cursor
INSUFF_PRIVS_REM - Insufficient privileges on remote objects referenced by the existing child cursor
REMOTE_TRANS_MISMATCH - The remote base objects of the existing child cursor do not match
USER1: select count(*) from table@remote_db
USER2: select count(*) from table@remote_db (Although the SQL is identical, the dblink pointed to by remote_db may be a private dblink which resolves
to a different object altogether)
LOGMINER_SESSION_MISMATCH
INCOMP_LTRL_MISMATCH
OVERLAP_TIME_MISMATCH - error_on_overlap_time mismatch
SQL_REDIRECT_MISMATCH - sql redirection mismatch
MV_QUERY_GEN_MISMATCH - materialized view query generation
USER_BIND_PEEK_MISMATCH - user bind peek mismatch
TYPCHK_DEP_MISMATCH - cursor has typecheck dependencies
NO_TRIGGER_MISMATCH - no trigger mismatch
FLASHBACK_CURSOR - No cursor sharing for flashback
ANYDATA_TRANSFORMATION - anydata transformation change
INCOMPLETE_CURSOR - incomplte cursor
TOP_LEVEL_RPI_CURSOR - top level/rpi cursor
In a Parallel Query invocation this is expected behaviour (we purposely do not share)
DIFFERENT_LONG_LENGTH - different long length
LOGICAL_STANDBY_APPLY - logical standby apply mismatch
DIFF_CALL_DURN - different call duration
BIND_UACS_DIFF - bind uacs mismatch
PLSQL_CMP_SWITCHS_DIFF - plsql compiler switches mismatch
CURSOR_PARTS_MISMATCH - cursor-parts executed mismatch
STB_OBJECT_MISMATCH - STB object different (now exists)
ROW_SHIP_MISMATCH - row shipping capability mismatch
PQ_SLAVE_MISMATCH - PQ slave mismatch
Check you want to be using PX with this reason code, as the problem could be caused by running lots of small SQL statements which do not really need PX. If you are on < 11i you may be hitting BUG4367986
TOP_LEVEL_DDL_MISMATCH - top-level DDL cursor
MULTI_PX_MISMATCH - multi-px and slave-compiled cursor
BIND_PEEKED_PQ_MISMATCH - bind-peeked PQ cursor
MV_REWRITE_MISMATCH - MV rewrite cursor
ROLL_INVALID_MISMATCH - rolling invalidation window exceeded
See NOTE: 557661.1 . This is caused by the rolling invalidation capability in DBMS_STATS. The child cannot be shared as it's invalidation window is exceeded.
OPTIMIZER_MODE_MISMATCH - optimizer mode mismatch
PX_MISMATCH - parallel query mismatch
If running 11.1.0.6 and RAC see BUG7352775. Check that if (on each instance) paralle_instance_groups is set then instance_groups is set to the same.
MV_STALEOBJ_MISMATCH - mv stale object mismatch
FLASHBACK_TABLE_MISMATCH - flashback table mismatch
LITREP_COMP_MISMATCH - literal replacement compilation mismatch
New in 11g (incomplete):
PLSQL_DEBUG - debug mismatch
Session has debugging parameter plsql_debug set to true
LOAD_OPTIMIZER_STATS - Load optimizer stats for cursor sharing
ACL_MISMATCH - Check ACL mismatch
FLASHBACK_ARCHIVE_MISMATCH - Flashback archive mismatch
LOCK_USER_SCHEMA_FAILED - Failed to lock user and schema
REMOTE_MAPPING_MISMATCH - Remote mapping mismatch
LOAD_RUNTIME_HEAP_FAILED - Runtime heap mismatch
HASH_MATCH_FAILED - Hash mismatch
Set to "Y" if sharing fails due to a hash mismatch, such as the case with mismatched histogram data or a range predicate marked as unsafe by literal replacement (See BUG3461251)
4. What further tracing is available ?
Solution:
In 10G it is possible to use CURSORTRACE to aid the investigation of why cursors are not being shared. This event should only be used under the guidance of support and the resultant trace file is undocumented. To get the trace for a particular SQL statement you first of all need to get the hash_value (See the above select from v$sqlarea). You then set the trace on using:-
(level 578/580 can be used for high level tracing (577=level 1, 578=level 2, 580=level 3)
This will write a trace file to user_dump_dest each time we try to reuse the cursor.
To turn off tracing use:-
Please note: BUG5555371 exists in 10.2 (fixed in 10.2.0.4) where cursor trace cannot fully be turned off and single line entries will still be made to the trace
file as a result. The w/a is to restart the instance. How invasive this BUG is depends on the executions of the cursor (and the size of the resultant trace file additions)
5. Are there any times when a high version count is expected even though BINDS are being used?
Solution:
Consider the following where cursor_sharing=SIMILAR
You will see several versions , each with no obvious reason for not being shared
Explanation:
One of the cursor sharing criteria when literal replacement is enabled with cursor_sharing as similar is that bind value should match initial bind value if the execution plan is going to change depending on the value of the literal. The reason for this is we _might_ get a sub optimal plan if we use the same cursor. This would typically happen when depending on the value of the literal optimizer is going to chose a different plan. Thus in this test case we have a predicate with > , if this was a equality we would always share the same child cursor. If application developers are ready to live with a sub-optimal plan and save on memory , then they need to set the parameter to force.
"The difference between SIMILAR and FORCE is that SIMILAR forces similar statements to share the SQL area without deteriorating execution plans.
Setting CURSOR_SHARING to FORCE forces similar statements to share the SQL area potentially deteriorating execution plans."
It is also possible to tell from 10046 trace (level 4/12 - BINDS) if a bind is considered to be unsafe
The flag oacfl2 in 9i and fl2 in 10g will show if a variable is unsafe.
|
产品
| ||
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/83180/viewspace-624357/ ,如需转载,请注明出处,否则将追究法律责任。