【转】Oracle Outline使用方法及注意事项
生活随笔
收集整理的這篇文章主要介紹了
【转】Oracle Outline使用方法及注意事项
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
概要?
Oracle Outline是用來保持SQL運(yùn)行計劃(execution plan)的一個工具。
Outline的主要使用在下面情況:?
1.?
為避免在升級后某些sql出現(xiàn)嚴(yán)重性能下降并且在短時間內(nèi)不能優(yōu)化的情況,?
我們能夠使用outline的功能將原生產(chǎn)庫中的sql運(yùn)行計劃實施在新的數(shù)據(jù)庫上。?
2.?
為避免SQL的運(yùn)行計劃在統(tǒng)計數(shù)據(jù)不準(zhǔn)確的情況(如未能及時收集表或索引的統(tǒng)計信息)下導(dǎo)致變化從而引起的性能減少。?
3.?
避免大規(guī)模分布實施的應(yīng)用出現(xiàn)數(shù)據(jù)庫版本號、配置等差別引起的優(yōu)化器產(chǎn)生不同的運(yùn)行計劃。?
4.?
某些Bug引起優(yōu)化器生成較差的運(yùn)行計劃。在bug修復(fù)前我們能夠使用outline來強(qiáng)制SQL的運(yùn)行計劃的正確。?
Outline的機(jī)制是將所須要的運(yùn)行計劃的hint保存在outline的表中。當(dāng)運(yùn)行SQL時,Oracle會與outline中的SQL比較,假設(shè)該SQL有保存的outline,則通過保存的hint生成運(yùn)行計劃。?
Outline的使用注意事項?
Outline的使用須要注意下面事項。?
1.?
Outln用戶是一個很重要的系統(tǒng)用戶。其重要性跟sys,system一樣。
2.?
優(yōu)化器通過Outline生成運(yùn)行計劃前提是outline內(nèi)全部hint都有效的。如:索引沒有創(chuàng)建的前提下,索引的hint是失效的。導(dǎo)致該SQL的outline計劃不會被使用。
3.?
參數(shù)Cursor_sharing=force時不能使用outline。?
4.?
literial sql的共享程度不高,Outline針對綁定變量的sql較好。
5.?
創(chuàng)建outline須要有create any outline的權(quán)限。?
6.?
要注意從CBO的角度來看,數(shù)據(jù)庫表和索引的統(tǒng)計信息是隨著數(shù)據(jù)量的變化而不斷改變的。
Outline使用舉例?
本文舉例說明怎樣使用outline,而且將outline的內(nèi)容從8i遷移到10g的數(shù)據(jù)庫上使用。?
操作步驟以scott用戶為例說明。
8i,10g中在scott用戶下創(chuàng)建測試表以說明outline的使用.?
Login as scott?
Create table t_test(col1 varchar2(2));?
1.?
確定8i生產(chǎn)庫的db,listener處于關(guān)閉的狀態(tài)。
2.?
啟動8i生產(chǎn)庫instance.?
3.?
8i庫使用system用戶登陸,賦create any outline權(quán)限給sql運(yùn)行用戶。?
Grant create any outline to scott;?
4.?
8i庫使用scott用戶登陸。?
Create outline t_ol1 for category special on select * from t_test where col1=’00’;?
T_ol1àoutline name?
(注意每一個outline都須要使用唯一的名字,不能反復(fù))?
Specialàoutline所屬的類(category)?
Select * from t_test where col1=’00’;à須要保存outline的sql?
5.?
10g,8i庫Unlock并改動outlin用戶口令。
Alter user outln identified by outln account unlock;?
6.?
在8i庫使用outln用戶,導(dǎo)出outline數(shù)據(jù)。?
Exp outln/outln tables=ol/$ ol/$hints file=ol.dmp log=ol_exp.log?
將export的數(shù)據(jù)復(fù)制到10g庫所在機(jī)器?
7.?
在10g庫使用outln用戶導(dǎo)入outline數(shù)據(jù)?
imp outln/outln file=ol.dmp ignore=y log=ol_imp.log?
8.?
在10g庫使用sys用戶更新ouline的signature?
connect sys/manager?
exec dbms_outln.update_signatures;?
啟用stored outline?
alter system set use_stored_outlines=special;?
à指定outline category?
9.?
檢測outline是否被使用?
connect scott/tiger?
create index I_test on t_test (col1);?
à創(chuàng)建索引。以改變運(yùn)行計劃?
explain plan for select * from t_test where col1=’00’;?
@?
PLAN_TABLE_OUTPUT?
Plan hash value: 4036493941?
----------------------------------------------------------------------------?
| Id? | Operation???????????????????????????????????????? | Name????? | Rows? | Bytes????? | Cost (%CPU)| Time???? |?
----------------------------------------------------------------------------?
|?? 0 | select STATEMENT?????????????????????? |???????????????? |???? 1????? |???? 3?????????? |? 1200?? (4)?????? | 00:00:17 |?
|*1? |TABLE ACCESS FULL?????????????????? | T_TEST |???? 1????? |???? 3?????????? |? 1200?? (4)????? | 00:00:17 |?
----------------------------------------------------------------------------?
Predicate Information (identified by operation id):?
---------------------------------------------------?
?? 1 - filter("COL1"='00')?
Note?
-----?
?? - outline "OL1" used for this statement?
à?
注意運(yùn)行計劃指出online已經(jīng)使用?
17 rows selected.?
說明outline已經(jīng)啟用。?
假設(shè)沒有outline的情況下應(yīng)該使用索引,運(yùn)行計劃例如以下。?
PLAN_TABLE_OUTPUT?
--------------------------------------------------------------------------------?
Plan hash value: 614253159?
---------------------------------------------------------------------------?
| Id? | Operation??????????????????????? | Name???? | Rows? | Bytes | Cost (%CPU)| Time???? |?
---------------------------------------------------------------------------?
|?? 0 | select STATEMENT???? |??????????????? |???? 1????? |????????? 3 |???? 3?? (0)????????? | 00:00:01 |?
|*? 1 |? INDEX RANGE SCAN| I_TEST |???? 1????? |????????? 3 |???? 3?? (0)????????? | 00:00:01 |?
---------------------------------------------------------------------------?
Predicate Information (identified by operation id):?
---------------------------------------------------?
?? 1 - access("COL1"='00')?
Outline維護(hù)?
停止db使用outline功能:?
alter system set use_stored_outlines=false;?
disable/enable詳細(xì)outline:?
alter outline ol_name disable;?
alter outline ol_name enable;?
刪除outline category:?
9i, 10g: exec dbms_outln.drop_by_cat(‘category_name’);?
8i: exec outln_pkg.drop_by_cat(‘category_name’);?
outline相關(guān)視圖?
dba_outlines?
檢查outline是否存在?
select?
name, category, owner from dba_outlines;?
dba_outline_hints?
這個視圖列出outline的hints內(nèi)容
Oracle Outline是用來保持SQL運(yùn)行計劃(execution plan)的一個工具。
我們能夠通過outline工具防止SQL運(yùn)行計劃在
數(shù)據(jù)庫環(huán)境變更(如統(tǒng)計信息,部分參數(shù)等)而引起變化。?Outline的主要使用在下面情況:?
1.?
為避免在升級后某些sql出現(xiàn)嚴(yán)重性能下降并且在短時間內(nèi)不能優(yōu)化的情況,?
我們能夠使用outline的功能將原生產(chǎn)庫中的sql運(yùn)行計劃實施在新的數(shù)據(jù)庫上。?
2.?
為避免SQL的運(yùn)行計劃在統(tǒng)計數(shù)據(jù)不準(zhǔn)確的情況(如未能及時收集表或索引的統(tǒng)計信息)下導(dǎo)致變化從而引起的性能減少。?
3.?
避免大規(guī)模分布實施的應(yīng)用出現(xiàn)數(shù)據(jù)庫版本號、配置等差別引起的優(yōu)化器產(chǎn)生不同的運(yùn)行計劃。?
4.?
某些Bug引起優(yōu)化器生成較差的運(yùn)行計劃。在bug修復(fù)前我們能夠使用outline來強(qiáng)制SQL的運(yùn)行計劃的正確。?
Outline的機(jī)制是將所須要的運(yùn)行計劃的hint保存在outline的表中。當(dāng)運(yùn)行SQL時,Oracle會與outline中的SQL比較,假設(shè)該SQL有保存的outline,則通過保存的hint生成運(yùn)行計劃。?
Outline的使用注意事項?
Outline的使用須要注意下面事項。?
1.?
Outln用戶是一個很重要的系統(tǒng)用戶。其重要性跟sys,system一樣。
在不論什么情況下都不建議用戶刪除outln。否則會引起數(shù)據(jù)庫錯誤。
?
2.?
優(yōu)化器通過Outline生成運(yùn)行計劃前提是outline內(nèi)全部hint都有效的。如:索引沒有創(chuàng)建的前提下,索引的hint是失效的。導(dǎo)致該SQL的outline計劃不會被使用。
?
3.?
參數(shù)Cursor_sharing=force時不能使用outline。?
4.?
literial sql的共享程度不高,Outline針對綁定變量的sql較好。
針對literial sql的情況,須要每條sql都生成outline。
?
5.?
創(chuàng)建outline須要有create any outline的權(quán)限。?
6.?
要注意從CBO的角度來看,數(shù)據(jù)庫表和索引的統(tǒng)計信息是隨著數(shù)據(jù)量的變化而不斷改變的。
固定的運(yùn)行計劃在某些時段并不一定是最優(yōu)的運(yùn)行計劃。
所以outline的使用是要依據(jù)詳細(xì)情況來決定的。
?
Outline使用舉例?
本文舉例說明怎樣使用outline,而且將outline的內(nèi)容從8i遷移到10g的數(shù)據(jù)庫上使用。?
操作步驟以scott用戶為例說明。
?
8i,10g中在scott用戶下創(chuàng)建測試表以說明outline的使用.?
Login as scott?
Create table t_test(col1 varchar2(2));?
1.?
確定8i生產(chǎn)庫的db,listener處于關(guān)閉的狀態(tài)。
?
2.?
啟動8i生產(chǎn)庫instance.?
3.?
8i庫使用system用戶登陸,賦create any outline權(quán)限給sql運(yùn)行用戶。?
Grant create any outline to scott;?
4.?
8i庫使用scott用戶登陸。?
Create outline t_ol1 for category special on select * from t_test where col1=’00’;?
T_ol1àoutline name?
(注意每一個outline都須要使用唯一的名字,不能反復(fù))?
Specialàoutline所屬的類(category)?
Select * from t_test where col1=’00’;à須要保存outline的sql?
5.?
10g,8i庫Unlock并改動outlin用戶口令。
注意,outln用戶的口令能夠改動可是outln用戶不能刪除。?
Alter user outln identified by outln account unlock;?
6.?
在8i庫使用outln用戶,導(dǎo)出outline數(shù)據(jù)。?
Exp outln/outln tables=ol/$ ol/$hints file=ol.dmp log=ol_exp.log?
將export的數(shù)據(jù)復(fù)制到10g庫所在機(jī)器?
7.?
在10g庫使用outln用戶導(dǎo)入outline數(shù)據(jù)?
imp outln/outln file=ol.dmp ignore=y log=ol_imp.log?
8.?
在10g庫使用sys用戶更新ouline的signature?
connect sys/manager?
exec dbms_outln.update_signatures;?
啟用stored outline?
alter system set use_stored_outlines=special;?
à指定outline category?
9.?
檢測outline是否被使用?
connect scott/tiger?
create index I_test on t_test (col1);?
à創(chuàng)建索引。以改變運(yùn)行計劃?
explain plan for select * from t_test where col1=’00’;?
@?
/rdbms/admin/utlxplp?
PLAN_TABLE_OUTPUT?
Plan hash value: 4036493941?
----------------------------------------------------------------------------?
| Id? | Operation???????????????????????????????????????? | Name????? | Rows? | Bytes????? | Cost (%CPU)| Time???? |?
----------------------------------------------------------------------------?
|?? 0 | select STATEMENT?????????????????????? |???????????????? |???? 1????? |???? 3?????????? |? 1200?? (4)?????? | 00:00:17 |?
|*1? |TABLE ACCESS FULL?????????????????? | T_TEST |???? 1????? |???? 3?????????? |? 1200?? (4)????? | 00:00:17 |?
----------------------------------------------------------------------------?
Predicate Information (identified by operation id):?
---------------------------------------------------?
?? 1 - filter("COL1"='00')?
Note?
-----?
?? - outline "OL1" used for this statement?
à?
注意運(yùn)行計劃指出online已經(jīng)使用?
17 rows selected.?
說明outline已經(jīng)啟用。?
假設(shè)沒有outline的情況下應(yīng)該使用索引,運(yùn)行計劃例如以下。?
PLAN_TABLE_OUTPUT?
--------------------------------------------------------------------------------?
Plan hash value: 614253159?
---------------------------------------------------------------------------?
| Id? | Operation??????????????????????? | Name???? | Rows? | Bytes | Cost (%CPU)| Time???? |?
---------------------------------------------------------------------------?
|?? 0 | select STATEMENT???? |??????????????? |???? 1????? |????????? 3 |???? 3?? (0)????????? | 00:00:01 |?
|*? 1 |? INDEX RANGE SCAN| I_TEST |???? 1????? |????????? 3 |???? 3?? (0)????????? | 00:00:01 |?
---------------------------------------------------------------------------?
Predicate Information (identified by operation id):?
---------------------------------------------------?
?? 1 - access("COL1"='00')?
Outline維護(hù)?
停止db使用outline功能:?
alter system set use_stored_outlines=false;?
disable/enable詳細(xì)outline:?
alter outline ol_name disable;?
alter outline ol_name enable;?
刪除outline category:?
9i, 10g: exec dbms_outln.drop_by_cat(‘category_name’);?
8i: exec outln_pkg.drop_by_cat(‘category_name’);?
outline相關(guān)視圖?
dba_outlines?
檢查outline是否存在?
select?
name, category, owner from dba_outlines;?
dba_outline_hints?
這個視圖列出outline的hints內(nèi)容
版權(quán)聲明:本文博客原創(chuàng)文章。博客,未經(jīng)同意,不得轉(zhuǎn)載。
轉(zhuǎn)載于:https://www.cnblogs.com/blfshiye/p/4665122.html
總結(jié)
以上是生活随笔為你收集整理的【转】Oracle Outline使用方法及注意事项的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快速幂 (转载,详细)
- 下一篇: OC-变量和数据类型