久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么解析Cursor和綁定變量

151次閱讀
沒有評論

共計 5283 個字符,預計需要花費 14 分鐘才能閱讀完成。

這篇文章將為大家詳細講解有關怎么解析 Cursor 和綁定變量,文章內容質量較高,因此丸趣 TV 小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

如下是我就這次演講的內容做的一點概括,里面也包含了我回答一些朋友的問題的郵件內容:

Oracle 里的 cursor 分為兩種:一種是 shared cursor,一種是 session cursor。

所謂的 shared cursor 就是指緩存在 library cache 里的一種 library cache object,說白了就是指緩存在 library cache 里的 sql 和匿名 pl/sql。它們是 oracle 緩存在 library cache 中的幾十種 library cache object 之一,它所屬于的 namespace 是 CRSR(也就是 cursor 的縮寫)。你信里提到的 parent cursor 和 child cursor 都是 shared cursor,它們都是以 library cache object handle 的方式存在 library cache 里,當一條 sql 第一次被執行的時候,會同時產生 parent cursor 和 child cursor,parent cursor 的 library cache object handle 的 heap 0 里會存儲其 child cursor 的地址,這個 sql 的執行計劃會存儲在上述 child cursor 的 library cache object handle 的 heap 6 中,第一次執行上述 sql 所產生的 parent cursor 和 child cursor 的過程也就是所謂的 硬解析 主要做的事情。如果上述 sql 再次執行,Oracle 只需要去掃描相應的 library cache object handle,找到上次硬解析后產生的 child cursor,把里面的 parse tree 和執行計劃直接拿過用就可以了,這就是所謂的 軟解析。

Oracle 里的第二種 cursor 就是 session cursor,session cursor 又分為三種:分別是 implicit cursor,explicit cursor 和 ref cursor。所謂的 session cursor 其實就是指的跟這個 session 相對應的 server process 的 PGA 里(準確的說是 UGA)的一塊內存區域(或者說內存結構),它的目的是為了處理且一次只處理一條 sql 語句(這里是指一個 implicit cursor 一次只處理一條 sql,explicit cursor 和 ref cursor 處理 sql 的數量是由你自己所控制)。

一個 session cursor 只能對應一個 shared cursor,而一個 shared cursor 卻可能同時對應多個 session cursor。

當某個 session cursor 和其對應的 shared cursor 建立關聯后,如果你把 cursor_space_for_time 調成 true,當一個 session cursor 處理完一條 sql 后,它就不會被 destroy,Oracle 會把其 cache 起來(我們稱之為 soft closed session cursor),這么做的目的是很明顯的,因為這個 soft closed 掉的 session cursor 已經和包含其執行計劃和 parse tree 的 shared cursor 建立了聯系,那么當在這個 session 中再次執行同樣的 sql 的時候,Oracle 就不再需要去掃描 library cache 了,直接把剛才已經 soft closed 掉的 session cursor 拿過來用就好了,這就是所謂的 軟軟解析。

最后我說一下特別容易混淆的 Oracle 里幾個關于 cursor 的參數的含義:

1、open_cursors

open_cursors 指的是在單個 session 中同時能以 open 狀態存在的 session cursor 的最大數量  

2、session_cached_cursors

session_cached_cursors 指的是單個 session 中同時能 cache 住的 soft closed session cursor 的最大數量

3、cursor_space_for_time

關于 cursor_space_for_time 有三點需要注意:1) 10.2.0.5 和 11.1.0.7 里它已經作廢了;2) 把它的值調成 true 后如果還同時用到了綁定變量,則由于 Bug 6696453 的關系,可能會導致 logical data corruption;3) 把它的值調成 true 后,所有的 child cursor 在執行完后依然會持有 library cache pin,直到其 parent cursor 關閉

首先我們來看一下 library cache object 所屬于的 namespace 的定義:

1. Library cache objects are grouped in namespaces according to their type.

2. Each object can only be of one type.

3. All the objects of the same type are in the same namespace.

4. A namespace may be used by more than one type.

5. The most important namespace is called cursor (CRSR) and houses the shared SQL cursors.

你在 obj$ 看到的關于 namespace 的解釋當然是不全的,因為像 shared cursor 這樣的 library cache object 根本就不在 obj$ 里。

所以實際上你可以這樣理解:namespace 是針對緩存在 library cache 里的 library cache object 來說的,那為什么 obj$ 里會有 namespace 的定義呢?—- 因為 library cache object 有一部分的來源就是來自于數據庫里已經存在的、固化的 object 的 metadata。

我們再來看一下 library cache object 所屬于的 namespace 的詳細說明:

Currently there are 64 different object types but this number may grow at any time with the introduction of new features. Examples of types are: cursor, table, synonym, sequence, index, LOB, Java source, outline, dimension, and so on. Not every type corresponds to a namespace. Actually, there are only 32 namespaces which, of course, are also subject to increase at any time.

What is a certainty is that all the objects of the same type will always be stored in the same namespace. An object can only be of one type, hence the search for an object in the library cache is reduced to a search for this object in the corresponding namespace.

Some namespaces contain objects of two or three different types. These are some of the most commonly used namespaces:

CRSR: Stores library objects of type cursor (shared SQL statements)

TABL/PRCD/TYPE: Stores tables, views, sequences, synonyms, procedure specifications, function specifications, package specifications, libraries, and type specifications

BODY/TYBD: Stores procedure, function, package, and type bodies

TRGR: Stores library objects of type trigger

INDX: Stores library objects of type index

CLST: Stores library objects of type cluster

The exact number and name of namespaces in use depends on the server features that are used by the application. For example, if the application uses Java, namespaces like JVSC (java source) and JVRE (Java resource) may be used, otherwise they will not be used.

Note: These namespaces do not store tables, clusters, or indexes as such, only the metadata is stored.

最后的結論是:我也看不到 KQD.H 的內容,所以我也無法知道 Oracle 里所有的 namespace 的準確 namespace id,但是其實你是可以通過 library cache dump 里的所有 namespace 的列表來猜出來的,因為這顯示是按 namespace id 來排序的。

可以通過 library cache dump 知道某個 Oracle 的版本下所有的 namespace,如下所示的是 9.2.0.6 的:

LIBRARY CACHE STATISTICS:
namespace  gets hit ratio  pins hit ratio  reloads  invalids
————– ——— ——— ——— ——— ———- ———-
CRSR  1078  0.860  4989  0.935  17  0
TABL/PRCD/TYPE  596  0.636  780  0.624  0  0
BODY/TYBD  1  0.000  0  0.000  0  0
TRGR  1  0.000  1  0.000  0  0
INDX  76  0.474  45  0.111  0  0
CLST  148  0.953  203  0.961  0  0
OBJE  0  0.000  0  0.000  0  0
PIPE  0  0.000  0  0.000  0  0
LOB  0  0.000  0  0.000  0  0
DIR  0  0.000  0  0.000  0  0
QUEU  30  0.700  30  0.700  0  0
OBJG  0  0.000  0  0.000  0  0
PROP  0  0.000  0  0.000  0  0
JVSC  0  0.000  0  0.000  0  0
JVRE  0  0.000  0  0.000  0  0
ROBJ  0  0.000  0  0.000  0  0
REIP  0  0.000  0  0.000  0  0
CPOB  0  0.000  0  0.000  0  0
EVNT  1  0.000  1  0.000  0  0
SUMM  0  0.000  0  0.000  0  0
DIMN  0  0.000  0  0.000  0  0
CTX  0  0.000  0  0.000  0  0
OUTL  0  0.000  0  0.000  0  0
RULS  0  0.000  0  0.000  0  0
RMGR  0  0.000  0  0.000  0  0
IFSD  1  0.000  0  0.000  0  0
PPLN  0  0.000  0  0.000  0  0
PCLS  0  0.000  0  0.000  0  0
SUBS  0  0.000  0  0.000  0  0
LOCS  0  0.000  0  0.000  0  0
RMOB  0  0.000  0  0.000  0  0
RSMD  0  0.000  0  0.000  0  0
JVSD  0  0.000  0  0.000  0  0
ENPR  0  0.000  0  0.000  0  0
RELC  0  0.000  0  0.000  0  0
STREAM  0  0.000  0  0.000  0  0
APPLY  0  0.000  0  0.000  0  0
APPLY SOURCE  0  0.000  0  0.000  0  0
APPLY DESTN  0  0.000  0  0.000  0  0
TEST  0  0.000  0  0.000  0  0
CUMULATIVE  1932  0.778  6049  0.888  17  0

從結果里看 9.2.0.6 是一共有 40 個 namespace。

關于怎么解析 Cursor 和綁定變量就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-20發表,共計5283字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 锡林浩特市| 双鸭山市| 论坛| 旅游| 伊川县| 巴青县| 连州市| 湖口县| 长治县| 新营市| 乡城县| 定远县| 花垣县| 白山市| 遵义市| 永清县| 九江县| 聂拉木县| 桦川县| 萍乡市| 哈密市| 彰武县| 铅山县| 施甸县| 渝北区| 陕西省| 南充市| 龙州县| 双柏县| 平昌县| 天柱县| 府谷县| 喀喇| 萨嘎县| 林芝县| 农安县| 宣汉县| 沧源| 沂水县| 涞水县| 扶绥县|