Oracle 11g結果集緩衝限制
有個不大的表 資料量大於百萬層級 這是類似IP位址範圍尋找. 表的查詢量很大.數即時產生,有時會被更新該表上的索引 主鍵和表 都被我KEEP進記憶體了。
查詢速度 基本保持在50-30毫秒之間.
該表的資料 一天要查500萬次以上.同時被重複查詢的次數也蠻多子.
鑒於這個原因 所以向開發人員提出 在SQL 增加提示 /*+ result_cache */
結論是 結果緩衝通過表的依賴而失效,也就是說相應表發生了資料變化那麼就重新從表擷取.相比時間 比普通45毫秒 高很多 達到945毫秒. 難道它不曉得從記憶體中擷取嗎? 還是覺得表資料有變化,直接從硬碟上讀取才是真!
declare
B1 VARCHAR2(20);
B2 NUMBER;
ORG NUMBER(10);
S TIMESTAMP;
E TIMESTAMP;
R TIMESTAMP;
begin
B2:=12;
B1:=668239581895;
FOR I IN 1..100 LOOP
S:=SYSTIMESTAMP;
SELECT /*+ result_cache */ USE_IP into IP
FROM (SELECT A.USE_IP
A.IP_TYPE
FROM BACK_IP A
WHEREA.IP_TYPE IN (3, 5, 9)
ANDIP_LEGN = B2
ANDA.START_IP <= B1
ANDA.END_IP >= B1
ORDER BYA.DISP_DATE DESC,
A.CREATE_TIME DESC)
WHERE ROWNUM <= 1;
E:=SYSTIMESTAMP;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(E-S));
DBMS_LOCK.SLEEP(10);
END LOOP;
END ;
測試結果 不很理想 波動性太大了.
+00000000000:00:00.090374000
+00000000000:00:00.102860000
+00000000000:00:00.000237000
+00000000000:00:00.000139000
+00000000000:00:00.000135000
+00000000000:00:00.000163000
+00000000000:00:00.000170000
+00000000000:00:00.000206000
+00000000000:00:00.000173000
+000000000 00:00:00.000171000
+00000000000:00:00.000170000
+00000000000:00:00.000139000
+00000000000:00:00.000267000
+00000000000:00:00.000171000
+00000000000:00:00.000160000
+00000000000:00:00.000180000
+00000000000:00:00.000161000
+00000000000:00:00.000183000
+00000000000:00:00.000182000
+00000000000:00:00.000139000
+00000000000:00:00.000147000
+00000000000:00:00.000160000
+00000000000:00:00.000212000
+00000000000:00:00.000353000
+00000000000:00:00.094454000