使用spm固定sql执行计划

固定sql执行计划

var n number
begin
:n:=dbms_spm.load_plans_from_cursor_cache(sql_id=>'&sql_id', plan_hash_value=>&plan_hash_value, fixed =>'YES', enabled=>'YES');
end;
/

 

删除固定的执行计划:

To view all Plans associated with a particular handle:

select sql_handle, plan_name, accepted, fixed,optimizer_cost
from dba_sql_plan_baselines
where sql_handle='SYS_SQL_32814757f4b84f6b';


SQL_HANDLE                     PLAN_NAME                      ACC FIX OPTIMIZER_COST
------------------------------ ------------------------------ --- --- --------------
SYS_SQL_32814757f4b84f6b       SYS_SQL_PLAN_f4b84f6b94f2914b  YES NO  6
SYS_SQL_32814757f4b84f6b       SYS_SQL_PLAN_f4b84f6bbce35b3e  YES NO  6
 

Example 1: Drop all the plans associated with a particular sql_handle:
To drop all the plans associated with a sql_handle:

declare
xx PLS_INTEGER;
BEGIN
xx :=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_32814757f4b84f6b',plan_name=>null);
END;
/

PL/SQL procedure successfully completed.
Note that there are now no plans:

 

SQL> select sql_handle, plan_name, accepted, fixed,optimizer_cost
from dba_sql_plan_baselines
where sql_handle='SYS_SQL_32814757f4b84f6b';

no rows selected

Example 2: Drop a baseline with a specific plan name
To drop only a specific baseline with specific plan_name, you can use the DROP_SQL_PLAN_BASELINE Function. This function drops a single plan, or all plans associated with a SQL statement. The syntax is :

DBMS_SPM.DROP_SQL_PLAN_BASELINE (
sql_handle IN VARCHAR2 := NULL,
plan_name IN VARCHAR2 := NULL)
RETURN PLS_INTEGER;
To use this in the example above:

declare
xx PLS_INTEGER;
BEGIN
xx :=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_32814757f4b84f6b',plan_name=>'SYS_SQL_PLAN_f4b84f6bbce35b3e');
END;
/

Example 3: Drop the entire SQL PLAN MANAGEMENT Repository
The following PL/SQL code will drop the entire SQL PLAN MANAGEMENT Repository.

 

connect / as sysdba
select count(*) from dba_sql_plan_baselines;

declare
pgn number;
sqlhdl varchar2(30);
cursor hdl_cur is
select distinct sql_handle from dba_sql_plan_baselines;
begin
open hdl_cur;

loop
fetch hdl_cur into sqlhdl;
exit when hdl_cur%NOTFOUND;

pgn := dbms_spm.drop_sql_plan_baseline(sql_handle=>sqlhdl);
end loop;

close hdl_cur;
commit;
end;
/

select count(*) from dba_sql_plan_baselines;

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值