当前位置:网站首页>An example of SPM manual binding execution plan

An example of SPM manual binding execution plan

2022-06-24 03:11:00 laosu

background

oracle 11.2.0.4

primary sql A Don't walk index , select /*+ no_index(t1 idx_01)*/ from t1 where object_id=5;

Manually generate indexed SQL B Implementation plan of ,select /*+ index(t1 idx_01)*/ from t1 where object_id=5;

take B The execution plan of is bound to A, send SQL A Go to the index .

The detailed steps

see sql A Of SQL_ID and PLAN_HASH_VALUE

-- from v$sql  View query  
select sql_id,plan_hash_value,sql_text,parse_calls,executions 
from v$sql 
where sql_text like 'select /*+ no_index(t1 idx_01)*%';
-- or sqlplus in , After execution sql After execution 
select * from table(dbms_xplan.display_cursor(null,null,'advanced'));  

establish sql A Of baseline, Generate sql_handle

declare
tmp number;
begin
tmp := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(sql_id => 'g3auf3vcmtr6z',plan_hash_value => 3910739905,enabled => 'NO'); 
end;
/

see baseline,A Of sql_handle

select sql_handle,plan_name,origin,enabled,accepted,sql_text 
from dba_sql_plan_baselines 
where sql_text like 'select /*+ no_index(t1 idx_01)*/%';

Generate what you need sql B Implementation plan of

 Execute multiple times as follows SQL
select /*+ index(t1 idx_01)*/ from t1 where object_id=5;
 obtain SQL B Of sql id  and plan_hash value, The above two methods are acceptable 
select * from table(dbms_xplan.display_cursor(null,null,'advanced'));
select sql_id,plan_hash_value,sql_text,parse_calls,executions 
from v$sql 
where sql_text like 'select /*+ index(t1 idx_01)*%';

take sql A Of sql_handle And B Associated with the execution plan

declare
tmp number;
begin
tmp := DBMS_SPM.load_plans_from_cursor_cache(sql_id => 'fsfyjhcrv6kwb', -- new sql_id ,sql B
plan_hash_value => 34099177, --new plan_hash_value, sql B
sql_handle => 'SQL_4fd8b0b98686fd73' -- primary sql Of sql_handle, sql A
);
end;
/
 or :
exec :tmp :=dbms_spm.load_plans_from_cursor_cache(sql_id=>'fsfyjhcrv6kwb',plan_hash_value=>34099177,sql_handle=>'SQL_4fd8b0b98686fd73');

see sql_handle, And delete the original execution plan

-- Check out the original SQL handle Implementation plan of 
select sql_handle,plan_name,origin,enabled,accepted,sql_text 
from dba_sql_plan_baselines 
where sql_handle='SQL_4fd8b0b98686fd73';
-- see baseline sql_handle Execution plan content 
select * from table(dbms_xplan.display_sql_plan_baseline(sql_handle=>'SQL_4fd8b0b98686fd73',plan_name=>'SQL_PLAN_4zq5hr638dzbmd147f332'));
-- Delete  
exec :tmp := dbms_spm.drop_sql_plan_baseline(sql_handle=>'SQL_4fd8b0b98686fd73',plan_name=>'SQL_PLAN_82y5y7jctbuxrb2fbea4c');

complete .

原网站

版权声明
本文为[laosu]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/10/20211015183322666q.html

随机推荐