1223 result cache,sql profile,sql patch
[20141223]result cache 與sql profile,sql patch.txt
--前面blog已經提到result cache的好處與缺點,對於第三方最佳化,sql profile可以改變穩定執行計劃,是否可以透過改變提示來穩定
--執行計劃,這樣對頻繁執行的語句較少邏輯讀,提高伺服器響應有積極意義。
--sql patch 也具有相似的作用,看看這種方式是否可行。
SCOTT@test> @ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.3.0 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SCOTT@test> exec sys.DBMS_RESULT_CACHE.flush
PL/SQL procedure successfully completed.
1.採用sql profile方式:
--假設程式頻繁執行如下語句,看是否可以加入result_cache提示:
select * from emp,dept where dept.deptno=emp.deptno;
--sql_id='ab5asdvqxfm27'
declare
v_sql CLOB;
begin
select distinct sql_text into v_sql from v$sql where sql_id='&sql_id';
dbms_sqltune.import_sql_profile(
name => 'profile_result_cache',
description => 'SQL profile created manually',
-- category => 'TEST',
sql_text => v_sql,
profile => sqlprof_attr(
'RESULT_CACHE'
),
replace => TRUE,
force_match => TRUE
);
end;
/
select * from emp,dept where dept.deptno=emp.deptno;
SCOTT@test> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID ab5asdvqxfm27, child number 0
-------------------------------------
select * from emp,dept where dept.deptno=emp.deptno
Plan hash value: 615168685
-----------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 8 (100)| 14 |00:00:00.01 | 15 | | | |
|* 1 | HASH JOIN | | 1 | 14 | 8 (13)| 14 |00:00:00.01 | 15 | 1035K| 1035K| 764K (0)|
| 2 | TABLE ACCESS FULL| DEPT | 1 | 6 | 4 (0)| 6 |00:00:00.01 | 8 | | | |
| 3 | TABLE ACCESS FULL| EMP | 1 | 14 | 3 (0)| 14 |00:00:00.01 | 7 | | | |
-----------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO")
Note
-----
- SQL profile profile_result_cache used for this statement
--可以發現sql profile已經生效,但是執行計劃沒有使用result_cache.
SCOTT@test> execute dbms_sqltune.drop_sql_profile(name => 'profile_result_cache')
PL/SQL procedure successfully completed.
2.採用sql patch模式:
declare
v_sql CLOB;
begin
select distinct sql_text into v_sql from v$sql where sql_id='&sql_id';
sys.dbms_sqldiag_internal.i_create_patch(
sql_text => v_sql,
hint_text => 'result_cache',
name => 'result_cache_patch');
end;
/
SCOTT@test> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID ab5asdvqxfm27, child number 0
-------------------------------------
select * from emp,dept where dept.deptno=emp.deptno
Plan hash value: 615168685
-----------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 8 (100)| 14 |00:00:00.01 | 15 | | | |
|* 1 | HASH JOIN | | 1 | 14 | 8 (13)| 14 |00:00:00.01 | 15 | 1035K| 1035K| 753K (0)|
| 2 | TABLE ACCESS FULL| DEPT | 1 | 6 | 4 (0)| 6 |00:00:00.01 | 8 | | | |
| 3 | TABLE ACCESS FULL| EMP | 1 | 14 | 3 (0)| 14 |00:00:00.01 | 7 | | | |
-----------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO")
Note
- SQL patch "result_cache_patch" used for this statement
--可以發現sql patch已經生效,但是執行計劃沒有使用result_cache.
SCOTT@test> exec dbms_sqldiag.drop_sql_patch('result_cache_patch');
PL/SQL procedure successfully completed.
3.後記:
--google發現如下連結:
As seen,no RESULT CACHE was used (also easily seen by time taken to count the rows) even if SQLPatch inplace. This is
actually result of a bug: Bug 16974854 : RESULT CACHE HINT DOES NOT WORK WITH SQL PATCH . Oracle also promised a patch
soon (and included in some BP for 11.2.0.3/4). It will eventually be fixed also in Oracle 12.2.x according to bug
description.
--看來要實行這個功能,使用者只能等了................
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1377511/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用RESULT CACHE加速SQL查詢效率SQL
- Oracle11g新特性:SQL Result Cache [zt]OracleSQL
- 【SQL Profile】coe_xfr_sql_profile.sql內容SQL
- print the result sqlSQL
- sql profileSQL
- sql profile使用SQL
- SQL Query Result Cache的使用和配置--Oracle 11G新特性SQLOracle
- sql tuning task和sql profileSQL
- ORACLE SQL PROFILE使用OracleSQL
- SQL PROFILE 測試SQL
- sql profile的使用SQL
- 自動/手動型別sql_profile(dbms_sqltune/coe_xfr_sql_profile.sql)型別SQL
- SQL Server profile使用技巧SQLServer
- SQL Profile 實驗03SQL
- SQL Profile 實驗02SQL
- SQL Profile 實驗01SQL
- 使用SQL Profile進行SQL優化案例SQL優化
- Oracle Query Result CacheOracle
- openGauss 支援SQL-PATCHSQL
- sql最佳化:使用sql profile最佳化sql語句SQL
- How to use sql result stored on shell variable?SQL
- 使用SQL Profile進行SQL最佳化案例SQL
- SQL Profile(第四篇)SQL
- SQL Profile(第三篇)SQL
- SQL Profile(第二篇)SQL
- sql_profile的使用(一)SQL
- Oracle 11.2.0.1 Result Cache 測試 - 12 DBMS_RESULT_CACHE管理包Oracle
- oracle 通過sql profile為sql語句加hintOracleSQL
- 通過SQL PROFILE自動優化SQL語句SQL優化
- 淺談Oracle Result CacheOracle
- SQL Profile(第一篇)SQL
- 檢視SQL PROFILE使用的HINTSQL
- sql tuning advisor(STA) 建議 建立sql profileSQL
- SQL PROFILE修改固定執行計劃SQL
- 使用sql profile固定執行計劃SQL
- query result cache in oracle 11gOracle
- MySQL Profile檢視SQL的資源使用MySql
- 控制執行計劃之-SQL Profile(一)SQL