怎么解析Cursor和綁定變量

這篇文章將為大家詳細(xì)講解有關(guān)怎么解析Cursor和綁定變量,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序制作、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了城廂免費(fèi)建站歡迎大家使用!

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

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里,當(dāng)一條sql第一次被執(zhí)行的時(shí)候,會(huì)同時(shí)產(chǎn)生parent cursor和child cursor,parent cursor的library cache object handle的heap 0里會(huì)存儲其child cursor的地址,這個(gè)sql的執(zhí)行計(jì)劃會(huì)存儲在上述child cursor的library cache object handle的heap 6中,第一次執(zhí)行上述sql所產(chǎn)生的parent cursor和child cursor的過程也就是所謂的"硬解析"主要做的事情。如果上述sql再次執(zhí)行,Oracle只需要去掃描相應(yīng)的library cache object handle,找到上次硬解析后產(chǎn)生的child cursor,把里面的parse tree和執(zhí)行計(jì)劃直接拿過用就可以了,這就是所謂的"軟解析"。

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

一個(gè)session cursor只能對應(yīng)一個(gè)shared cursor,而一個(gè)shared cursor卻可能同時(shí)對應(yīng)多個(gè)session cursor。

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

最后我說一下特別容易混淆的Oracle里幾個(gè)關(guān)于cursor的參數(shù)的含義:

1、open_cursors

open_cursors指的是在單個(gè)session中同時(shí)能以open狀態(tài)存在的session cursor的最大數(shù)量 

2、session_cached_cursors

session_cached_cursors指的是單個(gè)session中同時(shí)能cache住的soft closed session cursor的最大數(shù)量

3、cursor_space_for_time

關(guān)于cursor_space_for_time有三點(diǎn)需要注意:1) 10.2.0.5和11.1.0.7里它已經(jīng)作廢了;2) 把它的值調(diào)成true后如果還同時(shí)用到了綁定變量,則由于Bug 6696453的關(guān)系,可能會(huì)導(dǎo)致logical data corruption;3) 把它的值調(diào)成true后,所有的child cursor在執(zhí)行完后依然會(huì)持有l(wèi)ibrary cache pin,直到其parent cursor關(guān)閉

首先我們來看一下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$看到的關(guān)于namespace的解釋當(dāng)然是不全的,因?yàn)橄駍hared cursor這樣的library cache object根本就不在obj$里。

所以實(shí)際上你可以這樣理解:namespace是針對緩存在library cache里的library cache object來說的,那為什么obj$里會(huì)有namespace的定義呢?----因?yàn)閘ibrary cache object有一部分的來源就是來自于數(shù)據(jù)庫里已經(jīng)存在的、固化的object的metadata。

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

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.

最后的結(jié)論是:我也看不到KQD.H的內(nèi)容,所以我也無法知道Oracle里所有的namespace的準(zhǔn)確namespace id,但是其實(shí)你是可以通過library cache dump里的所有namespace的列表來猜出來的,因?yàn)檫@顯示是按namespace id來排序的。

可以通過library cache dump知道某個(gè)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

從結(jié)果里看9.2.0.6是一共有40個(gè)namespace。

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

網(wǎng)站標(biāo)題:怎么解析Cursor和綁定變量
鏈接URL:http://muchs.cn/article48/ijdohp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、電子商務(wù)、移動(dòng)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)