Up until 10g release 2, the only two locking and synchronization mechanisms available to the RDBMS engine were latches and enqueues. Oracle 10g release 2 introduces mutexs which replaces the library cache pin for shared cursors on platforms supporting atomic compare and swap operations (CAS). There is scant information on the library cache pin mutex on MetaLink or the internet at large for that matter, however Tanel Poder from Miracle A/S and the Oak Table provides some useful insights into this:-
Re: cursor: pin S wait on X
From: Tanel Põder
To:
Date: Sat, 29 Apr 2006 20:10:50 +0900 I studied the mutex stuff a bit when 10.2 came out, I'd say mutexes are less intelligent than latches. But thanks to that, they are more lightweight and thanks to quite large caches on modern CPUs we can afford having tons of them - allowing very fine grained locking.On my 32bit linux installation a mutex was 28 bytes in size, while a regular latch structure was 110 bytes. In theory every library cache child should have it's own mutex, but in practice I saw one case where two different child objects were protected by the same mutex - that was what library cache dump showed me anyway.Mutex also acts as a pin structure, so there's no need to do another memory write for pinning a cursor. Mutex allows immediate shared access to resources it protects, the old approach would mean getting a library cache latch in exclusive mode and then modifying the corresponding library cache child pin structure.Mutexes also don't maintain statistics on successful gets as latches do, only sleeps are registered.Thanks to all that, an immediately succeeding mutex get operation takes several times less CPU instructions (and hits possibly less memory stalls), from a 10gR2 perf tuning course I remember it was about 250 vs 50 CPU instructions on IA32 platform.Note that mutexes don't provide much benefit for poorly written applications, for most benefit your apps should avoid any kind of reparsing - keeping cursors open and cancelling them manually when interest in query results has ended.Tanel.
Mutexs are indeed light weight and Oracle states in some information that Oracle support provided me with (the document included 'external' in the title making me presume it is for public consumption) that the rationales for their introduction into the RDBMS engine are:-
1. They are smaller and much faster to get than latches.
2. It is fast and easy to create mutexes for individual structures leading to less contention on the mechanisms that protect the actual structures.
3. The mutex implementation is highly flexible in that components can define wait policy for individual mutexes.
4. Mutexes exhibit a dual nature ideal for pin type operations, many sessions can reference a mutex in shared mode where as only one session can hold a mutex in exclusive mode.
Activity on the library cache pin can be observed through waits appearing on events prefixed by cursor: pin, this is usually followed by something denoting the type of operation, e.g. cursor: pin S wait on X, pinning a cursor for an execute. The v$ views expose library cache pin activity through the v$mutex_sleep_history and v$mutex_sleeps views. When monitoring this mutex, the most important thing to keep an eye for is the amount of time waited on cursor pin events as opposed to the number of events. Large wait times can be due to numerous child cursors being built beneath a parent cursor through cursor invalidation, bind variable variance, statements being aged out of the shared pool etc. In fact, v$sql_shared_cursor view gives the comprehensive range of scenarios that can cause cursors to be be re-parsed:-
SQL_IDADDRESSCHILD_ADDRESS
CHILD_NUMBERUN
BOUND_CURSOR
SQL_TYPE_MISMATCH
OPTIMIZER_MISMATCH
OUTLINE_MISMATCH
STATS_ROW_MISMATCH
LITERAL_MISMATCH
SEC_DEPTH_MISMATCH
EXPLAIN_PLAN_CURSOR
BUFFERED_DML_MISMATCH
PDML_ENV_MISMATCH
INST_DRTLD_MISMATCH
SLAVE_QC_MISMATCH
TYPECHECK_MISMATCH
AUTH_CHECK_MISMATCH
BIND_MISMATCH
DESCRIBE_MISMATCH
LANGUAGE_MISMATCH
TRANSLATION_MISMATCH
ROW_LEVEL_SEC_MISMATCH
NSUFF_PRIVS
INSUFF_PRIVS_REM
REMOTE_TRANS_MISMATCH
LOGMINER_SESSION_MISMATCH
INCOMP_LTRL_MISMATCH
OVERLAP_TIME_MISMATCH
SQL_REDIRECT_MISMATCH
MV_QUERY_GEN_MISMATCH
USER_BIND_PEEK_MISMATCH
TYPCHK_DEP_MISMATCH
NO_TRIGGER_MISMATCH
FLASHBACK_CURSOR
ANYDATA_TRANSFORMATION
INCOMPLETE_CURSOR
TOP_LEVEL_RPI_CURSOR
DIFFERENT_LONG_LENGTH
LOGICAL_STANDBY_APPLY
DIFF_CALL_DURN
BIND_UACS_DIFF
PLSQL_CMP_SWITCHS_DIFF
CURSOR_PARTS_MISMATCH
STB_OBJECT_MISMATCH
ROW_SHIP_MISMATCH
PQ_SLAVE_MISMATCH
TOP_LEVEL_DDL_MISMATCH
MULTI_PX_MISMATCH
BIND_PEEKED_PQ_MISMATCH
MV_REWRITE_MISMATCH
ROLL_INVALID_MISMATCH
OPTIMIZER_MODE_MISMATCH
PX_MISMATCHMV_STALE
OBJ_MISMATCH
FLASHBACK_TABLE_MISMATCH
LITREP_COMP_MISMATCH
Metalink technical note 438755.1 'Formated V$SQL_SHARED_CURSOR Report by SQLID or Hash Value' contains information on how to obtain useful reports from this view, it also provides other links to articles to assist in investigating shared cursor issues further. Its a shame that the treasure trove of Oracle internals hints and tips;http://www.ixora.com.au/ is no longer kept uptodate as I'm sure that Steve Adams would have provided some excellant technical details on this mutex much more eloquantly than I have in this posting here.
No comments:
Post a Comment