本篇內(nèi)容介紹了“怎么理解數(shù)據(jù)庫的初始化參數(shù)cursor_sharing”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
在桃城等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,營銷型網(wǎng)站,外貿(mào)網(wǎng)站建設(shè),桃城網(wǎng)站建設(shè)費用合理。一、Cursor_sharing 簡介:
這個參數(shù)是用來告訴Oracle在什么情況下可以共享游標,即SQL重用。
Cursor_sharing參數(shù)有3個值可以設(shè)置:
1)、EXACT:通常來說,exact值是Oracle推薦的,也是默認的,它要求SQL語句在完全相同時才會重用,否則會被重新執(zhí)行硬解析操作。
2)、SIMILAR:similar是在Oracle認為某條SQL語句的謂詞條件可能會影響到它的執(zhí)行計劃時,才會被重新分析,否則將重用SQL。
3)、FORCE:force是在任何情況下,無條件重用SQL。
備注:上面所說的SQL重用,僅僅是指謂詞條件不同的SQL語句,實際上這樣的SQL基本上都在執(zhí)行同樣的業(yè)務(wù)操作。
二、在Cursor_sharing參數(shù)值不同的時對SQL的影響:
2.1 創(chuàng)建實驗環(huán)境:
----首先創(chuàng)建一張woo表----
WOO@woo> create table woo (id int,name varchar2(10)); Table created. Elapsed: 00:00:00.06
---產(chǎn)生一些數(shù)據(jù)----
WOO@woo> insert into woo values(1,'aa'); 1 row created. Elapsed: 00:00:00.00 WOO@woo> insert into woo values(2,'bb'); 1 row created. Elapsed: 00:00:00.00 WOO@woo> insert into woo values(3,'cc'); 1 row created. Elapsed: 00:00:00.00 WOO@woo> insert into woo values (4,'dd'); 1 row created. Elapsed: 00:00:00.00 WOO@woo> commit; Commit complete. Elapsed: 00:00:00.00 WOO@woo> select * from woo; ID NAME ---------- ---------- 1 aa 2 bb 3 cc 4 dd Elapsed: 00:00:00.01
---創(chuàng)建下面實驗將要用到的三張表----
WOO@woo> create table woo_exact as select * from woo; Table created. Elapsed: 00:00:00.01 WOO@woo> create table woo_similar as select * from woo; Table created. Elapsed: 00:00:00.01 WOO@woo> create table woo_force as select * from woo; Table created. Elapsed: 00:00:00.00
---查看當前session的trace文件的路徑----
WOO@woo> SELECT d.Value || '/' || Lower(Rtrim(i.Instance, Chr(0))) || '_ora_' || 2 p.Spid || '.trc' AS "trace_file_name" 3 FROM (SELECT p.Spid 4 FROM V$mystat m, V$session s, V$process p 5 WHERE m.Statistic# = 1 6 AND s.Sid = m.Sid 7 AND p.Addr = s.Paddr) p, 8 (SELECT t.Instance 9 FROM V$thread t, V$parameter v 10 WHERE v.Name = 'thread' 11 AND (v.Value = 0 OR t.Thread# = To_Number(v.Value))) i, 12 (SELECT VALUE 13 FROM V$parameter 14 WHERE NAME = 'user_dump_dest') d; trace_file_name ------------------------------------------------------- /DBSoft/diag/rdbms/woo/woo/trace/woo_ora_37746.trc Elapsed: 00:00:00.01
2.2 cursor_sharing=exact的情況:
WOO@woo> alter session set cursor_sharing=exact; Session altered. Elapsed: 00:00:00.00 WOO@woo> alter session set sql_trace=true; Session altered. Elapsed: 00:00:00.00 WOO@woo> select * from woo_exact where id=1; ID NAME ---------- ---------- 1 aa Elapsed: 00:00:00.00 WOO@woo> select * from woo_exact where id=2; ID NAME ---------- ---------- 2 bb Elapsed: 00:00:00.01 WOO@woo> select * from woo_exact where id=3; ID NAME ---------- ---------- 3 cc Elapsed: 00:00:00.00 WOO@woo> select * from woo_exact where id=1; ID NAME ---------- ---------- 1 aa Elapsed: 00:00:00.00
----從下面的查詢可以看出執(zhí)行了兩次硬解析----
WOO@woo> select sql_text from v$sql where sql_text like 'select * from woo_exact where%'; SQL_TEXT --------------------------------------------------------------------------------------- select * from woo_exact where id=1 select * from woo_exact where id=3 select * from woo_exact where id=2 Elapsed: 00:00:00.05 NAME VALUE ---------------------------------------------------------------- ---------- ADG parselock X get attempts 0 ADG parselock X get successes 0 parse time cpu 326 parse time elapsed 307 parse count (total) 56211 parse count (hard) 1681 parse count (failures) 10 parse count (describe) 0 8 rows selected.
cursor_sharing=similar的情況:
WOO@woo> alter session set cursor_sharing=similar; Session altered. Elapsed: 00:00:00.00 WOO@woo> alter system flush shared_pool; System altered. Elapsed: 00:00:00.13 WOO@woo> select * from woo_similar where id=1; ID NAME ---------- ---------- 1 aa Elapsed: 00:00:00.01 WOO@woo> select * from woo_similar where id=4; ID NAME ---------- ---------- 4 dd Elapsed: 00:00:00.00 WOO@woo> select * from woo_similar where id=8; no rows selected Elapsed: 00:00:00.00
----在這里可以看到執(zhí)行兩次SQL查詢,只進行了一個硬解析----
WOO@woo> select sql_text from v$sql where sql_text like 'select * from woo_similar where %'; SQL_TEXT -------------------------------------------------------------------------------------------------------- select * from woo_similar where id=:"SYS_B_0" Elapsed: 00:00:00.02 WOO@woo> select name,value from v$sysstat where name like '%parse%'; NAME VALUE ---------------------------------------------------------------- ---------- ADG parselock X get attempts 0 ADG parselock X get successes 0 parse time cpu 374 parse time elapsed 352 parse count (total) 57024 parse count (hard) 2006 parse count (failures) 10 parse count (describe) 0 8 rows selected. Elapsed: 00:00:00.00 WOO@woo>
對于SIMILAR的情況,如果CBO發(fā)現(xiàn)被綁定變量的謂詞還有其他的執(zhí)行計劃可以選擇時,如果謂詞條件的值有變化,就將會產(chǎn)生一個新的子游標,而不是重用之前的SQL;如果謂詞沒有其他的執(zhí)行計劃可選擇,則忽略謂詞的值,重用之前的SQL。
上面的例子還不能足以說明該情況,接著下面的模擬:
cursor_sharing=force的情況
WOO@woo> alter session set cursor_sharing=force; Session altered. Elapsed: 00:00:00.00 WOO@woo> alter system flush shared_pool; System altered. Elapsed: 00:00:00.07 WOO@woo> alter session set sql_trace=true; Session altered. Elapsed: 00:00:00.02 WOO@woo> select * from woo_force where id=1; ID NAME ---------- ---------- 1 aa Elapsed: 00:00:00.00 WOO@woo> select * from woo_force where id=4; ID NAME ---------- ---------- 4 dd Elapsed: 00:00:00.00 WOO@woo> select * from woo_force where id=1; ID NAME ---------- ---------- 1 aa Elapsed: 00:00:00.00
----從下面的查詢中可以看出只進行了一次硬解析,而且使用了綁定變量----
WOO@woo> select sql_text from v$sql where sql_text like 'select * from woo_force where %'; SQL_TEXT ------------------------------------------------------------------------------------------- select * from woo_force where id=:"SYS_B_0" Elapsed: 00:00:00.02 WOO@woo> select name,value from v$sysstat where name like '%parse%'; NAME VALUE ---------------------------------------------------------------- ---------- ADG parselock X get attempts 0 ADG parselock X get successes 0 parse time cpu 379 parse time elapsed 355 parse count (total) 57385 parse count (hard) 2145 parse count (failures) 10 parse count (describe) 0 8 rows selected. Elapsed: 00:00:00.01
總結(jié):force是在任何情況下,無條件重用SQL。
“怎么理解數(shù)據(jù)庫的初始化參數(shù)cursor_sharing”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
名稱欄目:怎么理解數(shù)據(jù)庫的初始化參數(shù)cursor_sharing-創(chuàng)新互聯(lián)
當前路徑:http://jinyejixie.com/article0/dhccio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、網(wǎng)站建設(shè)、微信小程序、標簽優(yōu)化、網(wǎng)站設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容