[20190221]sql patch 問題.txt
[20190221]sql patch 問題.txt
--//連結 http://www.itpub.net/thread-2108398-1-1.html ,遇到的問題,重複測試看看.
1.環境:
SCOTT@book> @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
SCOTT@book> create table t01 as select * from dba_objects;
Table created.
SCOTT@book> create index ind_t01_object_id on t01(object_id);
Index created.
--//注:我的測試不能分析,分析執行計劃會選擇索引.
BEGIN
SYS.DBMS_SQLDIAG_INTERNAL.i_create_patch(
sql_text => 'select * from t01 where object_id between 10000 and 30000',
hint_text => 'INDEX(T01,IND_T01_OBJECT_ID)',
name => 't01_sql_patch');
END;
/
select * from t01 where object_id between 10000 and 30000;
--//可以發現依舊選擇全表掃描.
BEGIN
DBMS_SQLDIAG.drop_sql_patch(name =>'t01_sql_patch');
END;
/
--//這樣不行.
select /*+ index(t01) */ * from t01 where object_id between 10000 and 30000;
SCOTT@book> @ dpc '' outline
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 8x42dpxgg1fgp, child number 0
-------------------------------------
select /*+ index(t01) */ * from t01 where object_id between 10000 and
30000
Plan hash value: 1880243119
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 463 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| T01 | 26993 | 5456K| 463 (1)| 00:00:06 |
|* 2 | INDEX RANGE SCAN | IND_T01_OBJECT_ID | 26993 | | 62 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T01@SEL$1
2 - SEL$1 / T01@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_RS_ASC(@"SEL$1" "T01"@"SEL$1" ("T01"."OBJECT_ID"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID">=10000 AND "OBJECT_ID"<=30000)
--//注意提示是INDEX_RS_ASC(@"SEL$1" "T01"@"SEL$1" ("T01"."OBJECT_ID")).
--//改寫如下,以sys使用者執行.
BEGIN
SYS.DBMS_SQLDIAG_INTERNAL.i_create_patch(
sql_text => 'select * from t01 where object_id between 10000 and 30000',
hint_text => 'INDEX_RS_ASC(@"SEL$1" "T01"@"SEL$1" ("T01"."OBJECT_ID"))',
name => 't01_sql_patch');
END;
/
select * from t01 where object_id between 10000 and 30000;
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 043grz1fjh9s7, child number 0
-------------------------------------
select * from t01 where object_id between 10000 and 30000
Plan hash value: 1880243119
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 463 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| T01 | 26993 | 5456K| 463 (1)| 00:00:06 |
|* 2 | INDEX RANGE SCAN | IND_T01_OBJECT_ID | 26993 | | 62 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T01@SEL$1
2 - SEL$1 / T01@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID">=10000 AND "OBJECT_ID"<=30000)
-----
- dynamic sampling used for this statement (level=2)
- SQL patch "t01_sql_patch" used for this statement
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
33 rows selected.
--//OK,現在可以使用索引了.也就是sql patch不能使用平時的提示.
--//我個人認為最好使用sql profile,或者sql planbase...sql patch一般使用比較特殊的提示比如bind_ware,result_cache等等。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2636531/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20190221]使用nmap掃描埠的問題.txt
- ORACLE通過BIND_AWARE+SQL PATCH解決SQL繫結變數中資料傾斜的問題OracleSQL變數
- [20150611]優化sql遇到問題.txt優化SQL
- [20181007]12cR2 Using SQL Patch.txtSQL
- openGauss 支援SQL-PATCHSQL
- [20181119]使用sql profile優化問題.txtSQL優化
- [20220324]toad與sql profile使用問題.txtSQL
- [20150304]關於sql格式化問題.txtSQL
- 從SQL Server匯出txt檔案匯入Oralce遇到毫秒問題SQLServer
- [20120606]sql中的註解問題.txtSQL
- [20181007]12cR2 Using SQL Patch 2.txtSQL
- postgresql copy UNICODE txt 問題。SQLUnicode
- [20211221]分析sql語句遇到的問題.txtSQL
- [202021127]sql打補丁問題.txtSQL
- [20210929]sql打補丁使用rule提示問題.txtSQL
- [20130628]sql語句顯示不全的問題.txtSQL
- 1223 result cache,sql profile,sql patchSQL
- [20221008]sql profile最佳化失效問題.txtSQL
- [20150705]從AWR抽取有問題的sql語句.txtSQL
- [20230329]記錄除錯sql語句遇到的問題.txt除錯SQL
- [20210621]Driving site patch.txt
- SQL問題診斷SQL
- SQL星期數問題SQL
- SQL Where in list 問題SQL
- [20241110]使用xto10.sql指令碼遇到的問題.txtSQL指令碼
- [20130121]訪問v$sql_plan的出現ora-07445問題.txtSQL
- sql 模糊查詢問題SQL
- SQL面試題,快問快答!SQL面試題
- Navicat 匯出sql問題SQL
- 常見面試SQL問題面試SQL
- SQL最佳化問題SQL
- sql重複插入問題SQL
- pl/sql的HomeEnd問題SQL
- jivejdon sql語句問題SQL
- 一些SQL問題SQL
- SQL基礎教程問題SQL
- sql server left join問題SQLServer
- [20211229]toad下優化sql語句注意的問題.txt優化SQL