你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 11g执行计划固定-Baseline

[日期:2012-05-22] 来源:Linux社区  作者:coast_lichao [字体:大 中 小]
三,那么现在假设应用中的sql是未添加Hint的,sql_id为5kuqnnugsrhj3,并且它的执行计划不是最优的,现在我们想用plan hash:2317224448来固定它。
操作如下:
  1. SQL> set serveroutput on;  
  2. SQL>declare  
  3.   2  v_clob clob;  
  4.   3  v_sql_id varchar2(13);  
  5.   4  v_plan_hash_value number;  
  6.   5  v_fixed varchar2(3);  
  7.   6  v_enabled varchar2(3);  
  8.   7  begin  
  9.   8  v_sql_id := '&hint_sql_id';  
  10.   9  v_plan_hash_value := to_number('&hint_plan_hash_value');  
  11.  10  v_fixed := '&fixed';  
  12.  11  v_enabled := '&enabled';  
  13.  12  select sql_fulltext into v_clob  
  14.  13  from v$sql  
  15.  14  where sql_id='bd8mzf35svfm3'  
  16.  15  and child_number=0;  
  17.  16  dbms_output.put_line(v_clob);  
  18.  17  dbms_output.put_line(  
  19.  18  dbms_spm.load_plans_from_cursor_cache(  
  20.  19                                        sql_id=>v_sql_id,   
  21.  20                                        plan_hash_value=>v_plan_hash_value,  
  22.  21                                        sql_text=>v_clob,  
  23.  22                                        fixed=>v_fixed,  
  24.  23                                        enabled=>v_enabled));  
  25.  24  end;  
  26.  25  /  
  27. Enter value for hint_sql_id: b6k9pwv7pw0s0  
  28. old   8: v_sql_id := '&hint_sql_id';  
  29. new   8: v_sql_id := 'b6k9pwv7pw0s0';  
  30. Enter value for hint_plan_hash_value: 2317224448  
  31. old   9: v_plan_hash_value := to_number('&hint_plan_hash_value');  
  32. new   9: v_plan_hash_value := to_number('2317224448');  
  33. Enter value for fixed: YES  
  34. old  10: v_fixed := '&fixed';  
  35. new  10: v_fixed := 'YES';  
  36. Enter value for enabled: YES  
  37. old  11: v_enabled := '&enabled';  
  38. new  11: v_enabled := 'YES';  
  39. select department_name  
  40. from hr.departments dept  
  41. where department_id in (select  
  42. department_id from hr.employees emp)  
  43.   
  44. PL/SQL procedure successfully complete  
  1. 查看生成的sql baseline信息:  
  1. select signature,sql_handle,plan_name,origin,enabled,accepted,fixed,autopurge  
  2.    from dba_sql_plan_baselines where sql_text like'select department_name  
  3. from hr.departments dept%';  
  4.   
  5.  SIGNATURE SQL_HANDLE                     PLAN_NAME                      ORIGIN         ENA ACC FIX AUT  
  6. ---------- ------------------------------ ------------------------------ -------------- --- --- --- ---  
  7. 3.0216E+17 SYS_SQL_c9bc6fc0e997f27c       SQL_PLAN_cmg3gs3ntgwmwec845e1a MANUAL-LOAD    YES YES YES YES  
linux
相关资讯       Oracle入门教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款