若在library cache latch获得发生争用,就须等待latch: library cache事件。然后SQL才开始执行,此时转入library cache pin+lock(null模式) select value from v$parameter where name='cpu_count'; --32个cpu select rownum,name,gets from v$latch_children where name like '%library%'; --37个library cache 子锁存器,一般认为子锁存器数量是比cpu_count大的最小质数值,可以被 _KGL_LATCH_COUNT 参数控制 原因: 1.hard parsing或soft parsing过多,硬解析时除了检索library cache的hash chain费时间,还得花时间额外分配chunk。就算是仅有软解析,也会发生争用,因为其还有语法检查语义检查、库高速缓冲区检索这些过程,在这些过程中也得先获得library cache latch。这个等待伴随shared pool latch等待就是硬解析过多(因为要分配chunk),没有后者就应该仅是软解释过多。
2.High Versions Count,子游标过多,v$sqlarea的version_count字段显示有多少个子游标,或者v$sql的child_number字段,从0开始算的。bucket->hash chain->检索到这个文本对应的cursor,还得检索这个父cursor下面的几个子cursor,例如不同用户发出的相同sql就会有一样的父cursor,此时获得library cache latch的时间会延长。 High version counts can easily cause high contention for library cache latches. A process parsing a SQL statement with many versions (children cursors) will need to scan through all these children while holding on to a library cache latch. This means that other processes needing the same latch will have to wait and can lead to significant database-wide performance degradation. 3.SGA区发生OS层面的page out,
后续: 11g,这个等待事件library cache: mutex X就是早期的latch: library cache等待。10g后很多latch用mutex代替。_kks_use_mutex_pin=false可以禁止mutex)