Documente Academic
Documente Profesional
Documente Cultură
inthepaststoredoutlineswereusedtofixexecutionplans
in11gthenextleveltocontrolexecutionplansisimplemented
itspossibletoforcetheoptimizertouseoneormoreexecutionplansforastatement,
uncontrolledplanchangesaredisabled.
takeacloserlookatthefollowingexamplestestit!
moredetailscanbefoundinORACLEdocumentationOracleDatabasePerformanceTuning
GuideChapter15UsingSQLPlanManagement
http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/optplanmgmt.htm#BABEAFGG
Noteinhttp://support.oracle.comSQLPLANMANAGEMENT[ID456518.1]
sqlplanmanagement
RolandGraeff,Germany
testedon11.2
testtable
createtabletst(col1number,col2varchar2(20));
insertintotstvalues(1,'A');
insertintotstvalues(2,'B');
commit;
select/*RGFTST*/col2fromtstwherecol2='A';
totest/showtheusedexecutionplan
explainplanfor
select/*RGFTST*/col2fromtstwherecol2='A';
select*fromtable(dbms_xplan.display);
sampleoutput
/*
PLAN_TABLE_OUTPUT
Planhashvalue:4148258400
|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|
|0|SELECTSTATEMENT||2|24|3(0)|00:00:01|
|*1|TABLEACCESSFULL|TST|2|24|3(0)|00:00:01|
PredicateInformation(identifiedbyoperationid):
PLAN_TABLE_OUTPUT
1filter(COL2=A)
Note
dynamicsamplingusedforthisstatement
*/
selectsql_id
selectsql_id,plan_hash_value,sql_text
fromv$sql
wheresql_textlike'%RGFTST%'
/
usetheaccordinglysql_idinthenextplsqlblock
toputtheexecutionplantothesqlplanmanagement
SETSERVEROUTPUTON
DECLARE
my_plansPLS_INTEGER;
BEGIN
my_plans:=DBMS_SPM.load_plans_from_cursor_cache(
sql_id=>'8d6dshztauuct',fixed=>'YES');
DBMS_OUTPUT.put_line('PlansLoaded:'||my_plans);
END;
/
listthesqlplanbaselines
SELECTsql_handle,plan_name,enabled,accepted,fixed
FROMdba_sql_plan_baselines
/
createindex
createindexi1ontst(col2)
/
innormalcircumstancestheindexi1shouldbeused
tochecktheusedexecutionplan
explainplanfor
select/*RGFTST*/col2fromtstwherecol2='A';
select*fromtable(dbms_xplan.display);
sampleoutput
/*
PLAN_TABLE_OUTPUT
Planhashvalue:4148258400
|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|
|0|SELECTSTATEMENT||1|12|2(0)|00:00:01|
|*1|TABLEACCESSFULL|TST|1|12|2(0)|00:00:01|
PredicateInformation(identifiedbyoperationid):
PLAN_TABLE_OUTPUT
1filter(COL2=A)
Note
dynamicsamplingusedforthisstatement
SQLplanbaselineSYS_SQL_PLAN_a5df9d5502e4a954usedforthisstatement
*/
tochangeattributesforthissqlplan
SELECTsql_handle,plan_name,enabled,accepted,fixed
FROMdba_sql_plan_baselines
/
DECLARE
v_cntPLS_INTEGER;
BEGIN
v_cnt:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE(
sql_handle=>'SYS_SQL_67a764aaa5df9d55',
attribute_name=>'ENABLED',
attribute_value=>'NO');
DBMS_OUTPUT.PUT_LINE('Plansaltered:'||v_cnt);
END;
/
SELECTsql_handle,plan_name,enabled,accepted,fixed
FROMdba_sql_plan_baselines
/
toshowthechanges
explainplanfor
select/*RGFTST*/col2fromtstwherecol2='A';
select*fromtable(dbms_xplan.display);
sampleoutput
/*
PLAN_TABLE_OUTPUT
Planhashvalue:1816312439
|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|
|0|SELECTSTATEMENT||1|12|1(0)|00:00:01|
|*1|INDEXRANGESCAN|I1|1|12|1(0)|00:00:01|
PredicateInformation(identifiedbyoperationid):
PLAN_TABLE_OUTPUT
1access(COL2=A)
Note
dynamicsamplingusedforthisstatement
*/
toremovesqlplan
declare
drop_planPLS_INTEGER;
BEGIN
drop_plan
:=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_67a764aaa5df9d55',plan_name=>'SYS_SQL_PLAN_a5df9d5502e
END;
/
declare
drop_planPLS_INTEGER;
BEGIN
drop_plan:=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_67a764aaa5df9d55',plan_name=>null);
END;
/
export/transferbaselinestoadifferentinstance
createastagingtable
execute
dbms_spm.CREATE_STGTAB_BASELINE(table_name=>RGRAEFF_STAGE_BL,table_owner=>RGRAEFF)
exportthemtothestagingtable
variablevarvarchar2(30)
execute:var:=dbms_spm.PACK_STGTAB_BASELINE(table_name=>RGRAEFF_STAGE_BL
,table_owner=>RGRAEFF)
executedbms_output.put_line(Baselinesexportiert:||:var)
nowthistablecanbeexported/importedviadatapumptothetargetinstance
withdbms_spm.UNPACK_STG_TAB_BASELINEtheexportedbaselinescanbeloaded
removetesttables
droptabletstpurge;