library cache 的一些内部机制

查看数: 3232 | 评论数: 6 | 收藏 2
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2010-11-29 13:42

正文摘要:

Library cache是Shared pool的一部分,它几乎是Oracle内存结构中最复杂的一部分,主要存放shared curosr(SQL)和PLSQL对象(function,procedure,trigger)的信息,以及这些对象所依赖的table,index,view等对象 ...

回复

yuanfang 发表于 2012-10-2 11:03:00
Latches are the more restrictive mechanism, because they do not allow multiple
processes to inspect the protected data structure at the same time—they provide
for exclusive access only.[1] Locks allow for better concurrency, because they may
be held in a shared mode when the data structure is simply being inspected.
[1] This is a simplification. The redo copy latches can be shared, but this is hardware
dependent.
Another significant difference between locks and latches is request queuing.
Requests for locks are queued if necessary and serviced in order, whereas latches
do not support request queuing. If a request to get a latch fails because the latch
is busy, the process just continues to retry until it succeeds. So latch requests are
not necessarily serviced in order.
Because a latch can only be held by one process at a time, and because there is no
inherent concept of queuing, the latch data structure itself is very simple—
essentially just a single location in memory representing the state of the latch.
And because the latch data structure is so simple, the functions to get and release
a latch have very little work to do. By contrast, the data structures for locks are
much more sophisticated because of their support for queuing and concurrency.
So the functions to get, convert, and release locks have correspondingly more
work to do.
Of course, it is necessary for Oracle to ensure that only one process at a time can
modify the latch and lock data structures themselves. For latches this is easy.
Because each latch is just a single location in memory, Oracle is able to use the
TEST AND SET, LOAD AND CLEAR, or COMPARE AND SWAP instructions of
the underlying hardware's instruction set for its latch get operations. Because
these are simple machine instructions that are guaranteed to be atomic, no other
locking mechanism is needed. This simplicity makes latch gets very efficient.
Oracle's lock data structures, on the other hand, have several parts, and therefore
cannot be modified atomically. For this reason, Oracle actually protects operations
on locks with latches. The type of latch used varies depending on the type of lock.
For example, the cache buffer locks are indirectly protected by the cache buffers
chains latches, and the row cache enqueue locks are protected by the row cache
objects latch.
yuanfang 发表于 2012-9-28 14:31:44
明白了 “cursor:pin S和cursor:pin X相当于share和exclusive类型的library cache pin,cursor:pin S wait on X则表示share方式正在等待exclusive锁定” 的含义:
cursor:pin S 相当于share类型的library cache pin
cursor:pin X 相当于exclusive类型的library cache pin,
cursor:pin S wait on X 则表示share方式的library cache pin正在等待exclusive锁定
yuanfang 发表于 2012-9-27 13:37:20
Library cache lock有三种模式:null,share,exclusive,Library cache pin有两种模式:share,exclusive。

其它有一些地方说:Library cache pin 也有三种模式:null,share,exclusive。
比如:http://www.eygle.com/archives/20 ... ache_pin_grant.html

到底该如何理解呢?

yuanfang 发表于 2012-9-27 11:07:40
仔细读完之后,颇有收获。但是有两点不太明白:
1)SQL1: select * from emp;SQL2: select * from emp和select a.name from emp a,dept b where a.dept_id=b.id and b.name=:1;SQL1产生了两个子游标,也就是SQL文本相同的两个不同版本,他们同时依赖emp表。SQL2只有一个版本,因为每个游标最少有一个子游标,所以它只有一个子游标,并且同时依赖dept表和emp表。

2)从Oracle10g开始,Oracle正在逐步用mutex取代library cache中的latch,cursor:pin S和cursor:pin X相当于share和exclusive类型的library cache pin,cursor:pin S wait on X则表示share方式正在等待exclusive锁定。(这段话完全读不明白。)

还相老师和各位指教。谢谢。
oracle_ocm 发表于 2012-9-26 10:06:09
解析的很深刻,学习
weikingcm 发表于 2010-12-17 20:43:47
深度剖析啊。。。 学习
意见
反馈