[20181109]12c sqlplus rowprefetch引數5.txt
–//這幾天一直在探究設定sqlplus引數rowprefetch與arraysize的關係,有必要做一些總結以及一些小更正:
1.設定rowprefetch < arraysize 的情況最佳,因為這樣fetch的模式是
rowprefetch,arraysize,arraysize,,…,剩下的記錄.
–//比較符合需要的情況.
2.不建議設定rowprefetch >= arraysize的情況.因為這樣改變fetch的模式.
rowprefetch,(floor(rowprefetch/arraysize)+1)*arraysize,(floor(rowprefetch/arraysize)+1)*arraysize,…,剩下的記錄.
3.補充一點做1點點小小的更正.
–//計算公式不是ceil(rowprefetch/arraysize)*arraysize,而是(floor(rowprefetch/arraysize)+1)*arraysize.
–//這樣對於rowprefetch < arraysize該公式也適用.
4.補充例子說明:
–//測試 rowprefetch = arraysize的情況
SCOTT@78> @ver1
PORT_STRING VERSION BANNER
—————————— ————– ——————————————————————————–
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
–//資料庫11.2.0.4.但是我使用12c sqlplus做為客戶端,rowprefetch引數可以設定,測試一樣有效.
SCOTT@78>create table t as select rownum id1,1 id2 from dual connect by level<=23;
Table created.
grant EXECUTE ON dbms_lock to scott;
CREATE OR REPLACE FUNCTION SCOTT.sleep (seconds IN NUMBER)
RETURN NUMBER
AS
BEGIN
sys.DBMS_LOCK.sleep (seconds);
RETURN seconds;
END;
/
R:> cat aa.txt
set timing on
set arraysize &1
set rowprefetch &2
alter session set events `10046 trace name context forever, level 12`;
select rownum ,t.*,sleep(id2) n10,&&1 arraysize ,&&2 rowprefetch from t;
–select rownum ,emp.*,get_dept(deptno) c10,&&1 arraysize ,&&2 rowprefetch from emp;
alter session set events `10046 trace name context off`;
set timing off
–//執行指令碼時,第1個參數列示arraysize,第2個參數列示rowprefetch.
SCOTT@78> @ aa.txt 5 5
Session altered.
$ grep FETCH /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_22631.trc | grep plh=2402761124
FETCH #140395096751240:c=0,e=5005000,p=0,cr=3,cu=0,mis=0,r=5,dep=0,og=1,plh=2402761124,tim=1541729295424586
FETCH #140395096751240:c=2000,e=10010448,p=0,cr=1,cu=0,mis=0,r=10,dep=0,og=1,plh=2402761124,tim=1541729305494803
FETCH #140395096751240:c=1000,e=8007876,p=0,cr=1,cu=0,mis=0,r=8,dep=0,og=1,plh=2402761124,tim=1541729313586610
–//fetch 5,10,8. 而顯示行數5,10,8.
–//也就是rowprefetch=arraysize,第2次fetch是 2*arraysize.
–//這樣上面的公式也滿足要求.(floor(rowprefetch/arraysize)+1)*arraysize