使用RESULT CACHE加速SQL查詢效率
有以下幾個引數需要關注
點選(此處)摺疊或開啟
-
SQL> show parameter result_cache
-
-
NAME TYPE
-
------------------------------------ ----------------------
-
VALUE
-
------------------------------
-
client_result_cache_lag big integer
-
3000
-
client_result_cache_size big integer
-
0
-
result_cache_max_result integer
-
5
-
result_cache_max_size big integer
-
4M
-
result_cache_mode string
-
MANUAL
-
result_cache_remote_expiration integer
- 0
如果要使用result_cache的結果返回,需要在SQL查詢語句中加上HINT
/*+ RESULT_CACHE */
看下例:
點選(此處)摺疊或開啟
- set autotrace on
-
//第一次查詢,不用result cache
select prod_id,cust_id from sales where time_id between to_date('2000-01-01', 'YYYY-MM-DD') and to_date('2000-01-03','YYYY-MM-DD'); -
Statistics
----------------------------------------------------------
110 recursive calls
0 db block gets
1963 consistent gets
824 physical reads
0 redo size
63782 bytes sent via SQL*Net to client
2613 bytes received via SQL*Net from client
192 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
2854 rows processed - //第2次查詢
- select /*+ RESULT_CACHE */ prod_id,cust_id from sales where time_id between to_date('2000-01-01', 'YYYY-MM-DD') and to_date('2000-01-03','YYYY-MM-DD');
-
Execution Plan
----------------------------------------------------------
Plan hash value: 3529668017--------------------------------------------------------------------------------
----------------------------| Id | Operation | Name | Rows | Byt
es | Cost (%CPU)| Time |--------------------------------------------------------------------------------
----------------------------| 0 | SELECT STATEMENT | | 8503 | 1
49K| 1738 (1)| 00:00:21 || 1 | RESULT CACHE | 6bhrdwm7rcqr486gmz2qc71h5m | |
| | || 2 | TABLE ACCESS BY INDEX ROWID | SALES | 8503 | 1
49K| 1738 (1)| 00:00:21 || 3 | BITMAP CONVERSION TO ROWIDS| | |
| | ||* 4 | BITMAP INDEX RANGE SCAN | SALES_TIME_BIX | |
| | |--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------4 - access("TIME_ID">=TO_DATE(' 2000-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss
') AND"TIME_ID"<=TO_DATE(' 2000-01-03 00:00:00', 'syyyy-mm-dd hh24:mi:ss
'))
Result Cache Information (identified by operation id):
------------------------------------------------------1 - column-count=2; dependencies=(SH.SALES); attributes=(ordered); parameters
=(nls); name="select /*+ RESULT_CACHE */ prod_id,cust_id from sales where time_i
d between to_date('2000-01-01', 'YYYY-MM-DD') and to_date('200"Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
63782 bytes sent via SQL*Net to client
2613 bytes received via SQL*Net from client
192 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2854 rows processed
其中,6bhrdwm7rcqr486gmz2qc71h5m是Cache ID。
檢視使用了result cache的物件
點選(此處)摺疊或開啟
- select id,type,status,name from v$result_cache_objects;
-
ID TYPE STATUS
---------- -------------------- ------------------
NAME
--------------------------------------------------------------------------------
0 Dependency Published
SH.SALES19 Result Published
select /*+ RESULT_CACHE */ prod_id,cust_id from sales where time_id between to_d
ate('2000-01-01', 'YYYY-MM-DD') and to_date('2001 Result Invalid
SELECT /* DS_SVC */ /*+ dynamic_sampling(0) no_sql_tune no_monitoring optimizer_ID TYPE STATUS
---------- -------------------- ------------------
NAME
--------------------------------------------------------------------------------
features_enable(default) opt_param('parallel_exe2 Result Invalid
SELECT /* DS_SVC */ /*+ dynamic_sampling(0) no_sql_tune no_monitoring optimizer_
features_enable(default) opt_param('parallel_exe
清空RESULT CACHE
點選(此處)摺疊或開啟
- exec DBMS_RESULT_CACHE.FLUSH;
1)RAC中只能供自身例項使用,但如果標記為INVALID,則整個RAC下都為INVALID
2) 繫結變數一定要變數值相同;
3)部分函式如sysdate()不支援。
在PL/SQL中,也可以使用RESULT_CACHE,需要先宣告RESULT_CACHE RELIES_ON。詳情略。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22621861/viewspace-2087899/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql 查詢效率SQL
- 1223 result cache,sql profile,sql patchSQL
- Alluxio Local Cache 加速 Presto 查詢在 Uber 的應用UXREST
- mysql查詢效率慢的SQL語句MySql
- 查詢效率低下的sql的語句SQL
- SQL Query Result Cache的使用和配置--Oracle 11G新特性SQLOracle
- Oracle11g新特性:SQL Result Cache [zt]OracleSQL
- Oracle Query Result CacheOracle
- 在mysql查詢效率慢的SQL語句MySql
- 使用Bulk Collect提高Oracle查詢效率Oracle
- ORACLE 11g Result cache使用指南Oracle
- Oracle 11.2.0.1 Result Cache 測試 - 12 DBMS_RESULT_CACHE管理包Oracle
- 用並行查詢讓SQL Server加速執行並行SQLServer
- 淺談Oracle Result CacheOracle
- 資料庫查詢優化:使用explain分析sql語句執行效率資料庫優化AISQL
- oracle result cache 結果集快取的使用Oracle快取
- 【索引】Oracle查詢指定索引提高查詢效率索引Oracle
- SQL查詢語句使用 (轉)SQL
- MySQL最佳化之如何查詢SQL效率低的原因MySql
- 突破常識:SQL增加DISTINCT後查詢效率反而提高SQL
- 使用機器學習加速對非結構化資料的查詢-第1部分(使用BlazeIt加速聚合和限制查詢)機器學習
- 關聯查詢子查詢效率簡單比照
- cassandra查詢效率探討
- query result cache in oracle 11gOracle
- SQL查詢的:子查詢和多表查詢SQL
- print the result sqlSQL
- Java 中如何使用 SQL 查詢 TXTJavaSQL
- 使用SQL實現特殊查詢(1)SQL
- 【SQL查詢】集合查詢之INTERSECTSQL
- Oracle提高查詢效率的方法Oracle
- Mysql 查詢快取 query_cacheMySql快取
- library cache lock 阻塞程式查詢
- library cache pin 阻塞程式查詢
- 查詢Library Cache Pin等待原因
- Oracle 11.2.0.1 Result Cache 測試 - 1Oracle
- Oracle 11.2.0.1 Result Cache 測試 - 5Oracle
- Oracle 11.2.0.1 Result Cache 測試 - 6Oracle
- Oracle 11.2.0.1 Result Cache 測試 - 7Oracle