[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
- [20181007]12cR2 Using SQL Patch.txtSQL
- [20181007]12cR2 Using SQL Patch 2.txtSQL
- [202021127]sql打補丁問題.txtSQL
- [20181119]使用sql profile優化問題.txtSQL優化
- [20220324]toad與sql profile使用問題.txtSQL
- [20211221]分析sql語句遇到的問題.txtSQL
- [20221008]sql profile最佳化失效問題.txtSQL
- [20210621]Driving site patch.txt
- [20210929]sql打補丁使用rule提示問題.txtSQL
- openGauss 支援SQL-PATCHSQL
- [20231101]使用tpt seg2.sql指令碼問題.txtSQL指令碼
- [20221126]tpt pr.sql指令碼執行問題.txtSQL指令碼
- [20241110]使用xto10.sql指令碼遇到的問題.txtSQL指令碼
- [20211229]toad下優化sql語句注意的問題.txt優化SQL
- [20230329]記錄除錯sql語句遇到的問題.txt除錯SQL
- [20211229]sql語句包含中文儲存clob的編碼問題.txtSQL
- [20181217]strace使用問題.txt
- [20181204]bbed修改問題.txt
- [20190313]備份問題.txt
- [20180619]bbed verify問題.txt
- [20210812]windows xcopy問題.txtWindows
- SQL問題診斷SQL
- [20190116]rman的老問題.txt
- [20181206]toad 12小問題.txt
- [20180509]函式索引問題.txt函式索引
- [20190522]rman備份問題.txt
- [20181227]bbed的使用問題.txt
- [20220329]windows xcopy命令問題.txtWindows
- [20221203]sqlplus set trimspool 問題.txtSQL
- [20221107]除錯crontab問題.txt除錯
- [20221202]sqlplus set trimout 問題.txtSQL
- [20220623]linux 口令expire問題.txtLinux
- [20210303]bbed使用小問題.txt
- [20201221]spfile設定問題.txt
- Navicat 匯出sql問題SQL
- SQL最佳化問題SQL
- sql 模糊查詢問題SQL