Oracle 變量綁定與變量窺視合集系列一

Oracle?變量綁定與變量窺視合集》

數據庫環境

LEO1@LEO1> select * from v$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

PL/SQL Release 11.2.0.1.0 - Production

CORE? ? 11.2.0.1.0? ?? ?Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production


?

?用示例說明綁定變量的應用領域是OLTP而不是OLAP

變量綁定:這是一個老生常談的話題,我所理解的綁定就是執行計劃的綁定,我所理解的變量就是謂詞替換的變量。

變量綁定機制:要說機制不得不說一下SQL執行的過程,三部曲:解析?–>?執行?->?取操作,而綁定變量就發生在解析這一步,而解析又分成硬解析和軟解析。

硬解析:當一條SQL語句第一次執行時,首先生成執行計劃,并把這個執行計劃存放到shared_pool的library cache中,這個過程叫做硬解析。

軟解析:如果SQL語句已經被硬解析過了,那么可以直接從library cache中抽取現成的執行計劃來重用,這個過程叫做軟解析,目的減少生成執行計劃這方面的資源消耗。為什么這么說呢,硬解析會消耗一些系統資源,尤其是CPU的資源,從而影響系統的效率,如果能把這方面的影響消除,那么對系統當然是多多益善了,哈?多侃了幾句。

SQL詳細執行過程:當oracle接收到一條sql語句時,首先會把這條sql語句字符做成哈希值,然后到library cache中尋找是否有和這個哈希值相匹配的sql存在,如果有就直接使用這個sql的執行計劃去執行當前的sql語句,最后將結果返回給用戶。如果沒有找到相同的哈希值,oracle會認為這是一條新的sql,將會重新生成執行計劃來執行(在這個過程中先要檢查語法分析和語義分析),最后將結果返回給用戶。

實驗

下面我們演示一下綁定變量和非綁定變量在資源消耗上的差異

LEO1@LEO1> drop table leo1 purge;? ?? ?? ?? ?? ??清理環境

Table dropped.

LEO1@LEO1> drop table leo2 purge;? ?? ?? ?? ?? ?

Table dropped.

LEO1@LEO1> create table leo1 as select * from dba_objects;? ??創建leo1

Table created.

LEO1@LEO1> create table leo2 as select * from dba_objects;? ??創建leo2

Table created.

LEO1@LEO1> alter session set tracefile_identifier='bind_variable';? ??設置trace文件標識

Session altered.

LEO1@LEO1> alter session set sql_trace=true;? ?? ?啟動trace功能,追蹤sql資源消耗情況

Session altered.

LEO1@LEO1> begin

for i in 1..100 loop

execute immediate 'select * from leo1 where object_id=:i' using i;

end loop;

end;

/

PL/SQL procedure successfully completed.

我們對一條sql執行了100次并采用了綁定變量技術,oracle對這條sql只有一次硬解析,沒有軟解析,反復執行100次。

LEO1@LEO1> alter session set sql_trace=false;? ?? ?? ???關閉trace功能

Session altered.

LEO1@LEO1> select sql_text,parse_calls,loads,executions from v$sql where sql_text like 'select * from leo1 where %';

SQL_TEXT? ?? ?? ?? ?? ?? ?? ?? ?? ???PARSE_CALLS??LOADS? ?EXECUTIONS

-------------------------------------------------- ----------- -------------------------- ----------- ---------- ------------------

select * from leo1 where object_id=:i? ?? ?? ?1? ?? ?? ? 1? ?? ???100

SQL_TEXT:我們跟蹤的sql語句

PARSE_CALLS:硬解析+軟解析次數? ?? ? 1次? ?只有硬解析沒有軟解析

LOADS:硬解析次數? ?? ?? ?? ?? ?? ???1次

EXECUTIONS:執行次數? ?? ?? ?? ?? ???100次

雖說值隱藏在變量中,但在解析環節oracle認為是一樣的

[oracle@leonarding1 trace]$ tkprof LEO1_ora_16433_bind_variable.trc bind_variable.txt sys=no

TKPROF: Release 11.2.0.1.0 - Development on Fri Feb 1 13:18:08 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.??All rights reserved.

使用tkprof工具過濾和匯總trace文件的,sys=no?不輸出sys用戶遞歸語句,默認yes,實際上設置成no更具有可讀性

---------?下面是bind_variable.txt文件信息

********************************************************************************

SQL ID: 0b74y9utb0b6r? ?? ?? ?? ? #這就是SQL語句字符的哈希值

Plan Hash: 2716644435

select *

from

leo1 where object_id=:i

call? ???count? ?? ? cpu? ? elapsed? ?? ? disk? ?? ?query? ? current? ?? ???rows

------- ------??-------- ---------- ---------- ---------- ----------??----------

Parse? ?? ???1? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ???0

Execute? ??100?? ???0.01? ?? ? 0.01? ?? ?? ? 0? ?? ?? ? 1? ?? ?? ? 0? ?? ?? ???0

Fetch? ?? ???0? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ???0

------- ------??-------- ---------- ---------- ---------- ----------??----------

total? ?? ?101? ?? ?0.01? ?? ? 0.01? ?? ?? ? 0? ?? ?? ? 1? ?? ?? ? 0? ?? ?? ???0

Misses in library cache during parse: 1? ?? ???只有1次硬解析,反復執行100次

Optimizer mode: ALL_ROWS

Parsing user id: 85? ???(recursive depth: 1)

Rows? ???Row Source Operation

-------??---------------------------------------------------

? ?? ?0??TABLE ACCESS FULL LEO1 (cr=0 pr=0 pw=0 time=0 us cost=288 size=2484 card=12)

********************************************************************************

下面是一個非綁定變量的sql執行情況

LEO1@LEO1> alter session set sql_trace=true;? ?? ?? ?? ???啟動trace功能

Session altered.

LEO1@LEO1> begin

for i in 1..100 loop

execute immediate 'select * from leo2 where object_id='||i;

end loop;

end;

/

PL/SQL procedure successfully completed.

我們對一條sql執行了100次沒有采用綁定變量技術,oracle對這條sql要硬解析100次,執行100次,資源嚴重被sql解析所消耗,系統顯得緩慢不堪。

LEO1@LEO1> alter session set sql_trace=false;? ?? ?? ?? ??關閉trace功能

Session altered.

LEO1@LEO1> select sql_text,parse_calls,loads,executions from v$sql where sql_text like 'select * from leo2 where %' order by 1;

SQL_TEXT? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? PARSE_CALLS? ?? ?LOADS EXECUTIONS

-------------------------------------------------- ----------- ---------- ----------

select * from leo2 where object_id=1? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=10? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=100? ?? ?? ?? ?? ?? ?? ???1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=11? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=12? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=13? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=14? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=15? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=16? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=17? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=18? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=19? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=2? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=20? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=21? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=22? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=23? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=24? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=25? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=26? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=27? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=28? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=29? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=3? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=30? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=31? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=32? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=33? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=34? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=35? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=36? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=37? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=38? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=39? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=4? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=40? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=41? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=42? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=43? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=44? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=45? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=46? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=47? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=48? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=49? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=5? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=50? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=51? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=52? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=53? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=54? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=55? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=56? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=57? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=58? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=59? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=6? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=60? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=61? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=62? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=63? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=64? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=65? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=66? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=67? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=68? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=69? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=7? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=70? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=71? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=72? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=73? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=74? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=75? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=76? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=77? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=78? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=79? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=8? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=80? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=81? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=82? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=83? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=84? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=85? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=86? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=87? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=88? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=89? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=9? ?? ?? ?? ?? ?? ?? ?? ? 1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=90? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=91? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=92? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=93? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=94? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=95? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=96? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=97? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=98? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

select * from leo2 where object_id=99? ?? ?? ?? ?? ?? ?? ?? ?1? ?? ?? ? 1? ?? ?? ? 1

100 rows selected.

我們從動態性能視圖上可以看出oracle每執行一次sql,都要先硬解析1次之后在執行。這種沒有使用綁定變量技術在硬解析消耗上就比使用綁定變量技術多損耗100倍,如果執行的次數上萬?上億對系統性能的影響可想而知。

---------?我們來看看trace文件的內容

[oracle@leonarding1 trace]$ tkprof LEO1_ora_16433_bind_variable.trc bind_variable.txt sys=no

TKPROF: Release 11.2.0.1.0 - Development on Fri Feb 1 13:49:52 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.??All rights reserved.

********************************************************************************

SQL ID: 22r47f3t6w0td

Plan Hash: 2258638698

select *

from

leo2 where object_id=1

call? ???count? ?? ? cpu? ? elapsed? ?? ? disk? ?? ?query? ? current? ?? ???rows

------- ------??-------- ---------- ---------- ---------- ----------??----------

Parse? ?? ???1? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 1? ?? ?? ? 0? ?? ?? ???0

Execute? ?? ?1? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ???0

Fetch? ?? ???0? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ? 0? ?? ?? ???0

------- ------??-------- ---------- ---------- ---------- ----------??----------

total? ?? ???2? ?? ?0.00? ?? ? 0.00? ?? ?? ? 0? ?? ?? ? 1? ?? ?? ? 0? ?? ?? ???0

Misses in library cache during parse: 1

Optimizer mode: ALL_ROWS

Parsing user id: 85? ???(recursive depth: 1)

Rows? ???Row Source Operation

-------??---------------------------------------------------

? ?? ?0??TABLE ACCESS FULL LEO2 (cr=0 pr=0 pw=0 time=0 us cost=288 size=2484 card=12)

********************************************************************************

SQL ID: 9nb3n54fy0z8m

Plan Hash: 2258638698

select *

from

leo2 where object_id=2

********************************************************************************

SQL ID: 8mc705qymd7qs

Plan Hash: 2258638698

select *

from

leo2 where object_id=3

如上所示每個sql語句的SQL_ID都是不一樣的,都是相對獨立的,因此每執行1次就要解析1次,兩種情況對比結果顯示,綁定變量要比沒有綁定變量消耗的資源少的少,sql執行的次數越多,這種效果越明顯。所以我們說綁定變量本質就是用一個變量來代替謂詞常量,讓oracle只需要硬解析一次,后續sql都直接使用之前執行計劃來執行,這樣就省卻了很消耗資源的硬解析過程

下面討論綁定變量為什么適合于OLTP而不是OLAP

OLTP

1.適合OLTP系統架構

2.SQL簡單非常相似,結果集非常小,例如?只有謂詞部分不同,余下部分全部相同的SQL語句,這種情況下執行計劃都是一樣的,在執行計劃幾乎不變的情況下,oracle使用變量來代替謂詞常量,使用同一個執行計劃是非常合理的

3.SQL重復率很高,或者只有謂詞條件不同而已

4.DML操作頻繁

5.SQL語句執行條數多,條數越多減少硬解析越有意義

6.基于主鍵做查詢,還有等值查詢,唯一性查詢,這類查詢相對適合綁定變量

select? ?*? ?from??leonarding? ?where? ?id=:leo;

?

OLAP

1.不適合OLAP系統架構

2.SQL的執行計劃多變,會因為值的不同導致執行計劃的不同,可能第一次執行是一種執行計劃,第二次執行是另一種執行計劃,所以不適合進行綁定變量操作,會讓oracle盲目浪費大量資源消耗,SQL語句即使只有謂詞條件不同,oracle應然可能采取不同的執行計劃。

3.SQL重復率較低,大部分都是批量加載批量檢索的操作

4.數據聚合操作頻繁

5.SQL語句執行條數少,SQL硬解析對系統性能影響較小,綁定沒有意義

6.分區表相對不太適合綁定變量技術


?本文轉自 leonarding151CTO博客,原文鏈接:http://blog.51cto.com/leonarding/1131507,如需轉載請自行聯系原作者


本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/256648.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/256648.shtml
英文地址,請注明出處:http://en.pswp.cn/news/256648.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

(原創)對某國的一次滲透

文章均由自己原創,只是一直沒有在自己博客發表。本地附件也沒有了,我是從網上找來我的以前的投稿。 寫在之前的廢話:小菜技術能力不行,如果你覺得此文實在看不下去,還請PASS掉。如果你對我的文章有興趣,可以…

matlab常用函數——方程函數

八、插值函數、線性方程解函數和多項式函數 1)插值函數 interp1q :1維快速線性插值法 yi=interp1q(x,Y,xi) interp1q正常執行條件: (1)x單調遞增列向量 (2)Y為列向量or行數為length(x)(3)xi為列向量,如果xi值在x的坐標范圍外,返回NaN 實例: x=(-5:0.5:5); y=sin…

C/C++ | 字節對齊

目的:優化CPU訪問數據效率 類型轉換:未對齊時,嚴格一些的系統會報段錯誤,未報錯的話效率也會有所下降。 各種結構的對齊: 編譯器的區別: 其實字節對齊的細節和具體編譯器實現相關,但一般而言&am…

關于python測試webservice接口的視頻分享

現在大公司非常流行用python做產品的測試框架,還有對于一些快速原型產品的開發也好,很好地支持OO編程,代碼易讀。 Python的更新挺快的,尤其是第三方庫。 對于測試人員,代碼基礎薄弱,用python語言容易上手。…

matlab常用函數——文件操作函數

十一、基本文件操作函數 1)文件創建函數 filemaker :把文件名與文件中函數名分開 。 filesep :文件目錄分隔。 fileparts :把目標文件名拆分成字符串形式輸出 。 tempdir :返回系統暫存地址名 。 tempname :返回系統暫存文件名 。 fullfile :創建文件名 2)文件打…

Struts2中文件上傳下載實例

1.單文件上傳 1 jsp頁面&#xff1a;2 3 <!-- 單文件上傳 -->4 <form action"Fileupload.action" method"post"5 enctype"multipart/form-data">6 username:7 <input type"tex…

最優化課堂筆記06-無約束多維非線性規劃方法(續)

6.5共軛方向法 6.5.1 共軛方向 6.5.1 共軛梯度法 6.6單純形法(不考) 6.7最小二乘法 6.7.2 改進的高斯-牛頓最小二乘法

opengl微發展理解

1.什么是OpenGL? 一種程序&#xff0c;可以與界面和圖形硬件交互作用、一個開放的標準 2.軟件管道 請看上圖 - Apllication層 表示你的程序&#xff08;調用渲染命令。如opengl API&#xff09; -Abstraction層 表示畫圖接口&#xff08;如OpenGL API或者DirectX API&a…

MacosX 下GCC編譯指定版本的代碼

export MACOSX_DEPLOYMENT_TARGET10.6轉載于:https://www.cnblogs.com/lovelylife/p/5754226.html

最優化作業第六章——共軛梯度法和鮑爾法

共軛梯度法&#xff1a; 代碼&#xff1a; #導入模塊 from sympy import * import sympy as sp #將導入的模塊重新定義一個名字以便后續的程序進行使用 from numpy import * import numpy as npdef main():#本例是利用共軛梯度法進行最優化x1,x2,alpha symbols("x1,x2,…

酒鬼隨機漫步(一個矢量類)

摘要: 閱讀全文這是一個定義的一個矢量類&#xff0c; 然后用矢量類模擬一個酒鬼的隨機漫步 問題很簡單&#xff0c; 實現也不麻煩&#xff0c; 但是這個小程序卻可以呈現出許多語法知識。而且代碼風格也不錯&#xff0c;因此保存在了這篇博客中。 建議&#xff1a; 1. 類的聲…

對高并發流量控制的一點思考

前言 在實際項目中&#xff0c;曾經遭遇過線上5WQPS的峰值&#xff0c;也在壓測狀態下經歷過10WQPS的大流量請求&#xff0c;本篇博客的話題主要就是自己對高并發流量控制的一點思考。 應對大流量的一些思路 首先&#xff0c;我們來說一下什么是大流量&#xff1f; 大流量&…

ndk學習19: 使用Eclipse調試so

1. 設置調試選項在AndroidManifest文件加入允許調試android:debuggable"true" 此時編譯項目會多出:2. 配置調試代碼把需要調試的代碼,放如按鈕事件中,如果放在OnCreate會導致連接調試器時,代碼已經跑完了Button btnTest (Button)findViewById(R.id.button1);btnT…

Inside the C++ Object Model | Outline

《Inside the C Object Model&#xff08;C對象模型&#xff09;》&#xff0c;這是一本灰常不錯的書&#xff01; CSDN下載頁面&#xff08;中文&#xff0c;侯捷譯&#xff09; 豆瓣評論 讀書筆記目錄如下&#xff08;不定時更新&#xff09;&#xff1a; 轉載于:https://www…

最優化課程筆記07——約束問題的非線性規劃方法(重點:拉格朗日乘子法和懲罰函數法)

7.1 間接法&#xff1a;約束轉化為無約束問題&#xff08;含一個重點&#xff1a;拉格朗日乘子法&#xff09; 當維數多的時候不適用 7.1.2拉格朗日乘子法&#xff08;重點&#xff09; 7.1.2.1 等式約束問題 7.1.2.2 不等式約束問題 7.1.3 懲罰函數法&#xff08;內懲罰函數法…

工業相機:傳感器尺寸與像元尺寸的關系

相同分辨率的工業相機&#xff0c;傳感器面積越大&#xff0c;則其單位像素的面積也越大&#xff0c;成像質量也會越好。同樣的500萬像素的工業相機&#xff0c;2/3”的傳感器成像質量就要優于1/2”的。一般來說&#xff0c;工業相機的靶面大小&#xff0c;如果要求不是太嚴格&…

macOS下安裝ipython

macOS下sudo安裝ipython&#xff0c;會提示限錯誤&#xff1a; [Errno 1] Operation not permitted: /tmp/pip-Elrhse-uninstall/System/Library... 解決方法&#xff1a; pip install ipython --user -U 參考&#xff1a; http://chaishiwei.com/blog/994.html 本文轉自 h2app…

結構化查詢語言包含哪些方面?

結構化查詢語言SQL&#xff08;STRUCTURED QUERY LANGUAGE&#xff09;是最重要的關系數據庫操作語言&#xff0c;并且它的影響已經超出數據庫領域&#xff0c;得到其他領域的重視和采用&#xff0c;如人工智能領域的數據檢索&#xff0c;第四代軟件開發工具中嵌入SQL的語言等。…

Opencv 找輪廓并畫出相應的矩形

找輪廓參考以下大神的&#xff0c;對于里面的方法和結果存儲解釋的很清楚&#xff1b; http://blog.csdn.net/gubenpeiyuan/article/details/44922413 缺少的是畫相應包圍矩形的&#xff0c;其中找矩形用最小外接矩形函數cvMinAreaRect2 。 CvBox2D rect; CvPoint2D32f Corner…