sql profile固定执行计划(Automatic)

--在我们无法修改源代码的时候,我们可以采用sqlprofile来改变执行计划
--新增一张测试表
create table test_emp as select * from scott.emp;

--新建索引
create index idx_001 on test_emp(empno);

--下面的语句正常是要走全表扫描的
select /*+ no_index(test_emp idx_001) */ * from test_emp where empno=7521;

select * from v$sql t where t.SQL_TEXT like '%select /*+ no_index(test_emp idx_001) */ * from test_emp where empno=7521%'
select * from table(dbms_xplan.display_cursor('6xgya67tytkax',0,'ADVANCED ALLSTATS LAST PEEKED_BINDS'));

--创建一个调优任务
declare 
  my_task_name varchar2(30);
  my_sqltext clob;
begin
    my_sqltext:='select /*+ no_index(test_emp idx_001) */ * from test_emp where empno=7499';
    my_task_name:=dbms_sqltune.create_tuning_task(
                            sql_text=>my_sqltext,
                            user_name => 'X86',
                            scope=>'COMPREHENSIVE',
                            time_limit=>60,
                            task_name=>'my_sql_tuning_task_2',
                            description=>'Task to tune a query on table test_emp');
end;
 
--执行这个调优任务                       
begin 
    dbms_sqltune.execute_tuning_task(task_name => 'my_sql_tuning_task_2');    
end;                       

--发现有可用的调优方案                          
select dbms_sqltune.report_tuning_task('my_sql_tuning_task_2') from dual  

 

--应用这个调优方案 
begin dbms_sqltune.accept_sql_profile(task_name =>
            'my_sql_tuning_task_2', task_owner => 'X86', replace => TRUE,force_match => true);   end;                 
                            
                            
begin
    dbms_sqltune.drop_sql_profile('SYS_SQLPROF_01602055212c0000');
    dbms_sqltune.drop_tuning_task('my_sql_tuning_task_2');
end;
    
    

 

转载于:https://www.cnblogs.com/xuzhong86/p/7977265.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值