17站长网

17站长网 首页 数据库 oracle 查看内容

oracle sql_profile绑定异常处置

2023-3-21 14:47| 查看: 1194 |来源: 互联网

oracle sql_profile绑定异常处置:  一 建立测试表  create table a nologging as select * from all_objects;  二 准备工作  找到sql_Id='aq03 ...

oracle sql_profile绑定异常处置:

  一 建立测试表

  create table a nologging as select * from all_objects;

  二 准备工作

  找到sql_Id='aq03p7muwgvq5'

  select  * from V$sql where sql_text like '% from a where object_id=3%';

  找到全表的outline:

  方法一:dba_hist_sql_plan/v$sql_plan都可以

  select extractvalue(value(d), '/hint') as outline_hints

  from

  xmltable('/*/outline_data/hint'

  passing (

  select

  xmltype(other_xml) as xmlval

  from

  dba_hist_sql_plan

  where

  sql_id = '&sql_id'

  and plan_hash_value=&plan_hash_value

  and other_xml is not null)) d

  方法二:

  select * from dbms_xplan.display_awr('aq03p7muwgvq5',0,'outline');

  /*+

      BEGIN_OUTLINE_DATA

      IGNORE_OPTIM_EMBEDDED_HINTS

      OPTIMIZER_FEATURES_ENABLE('11.2.0.4')

      DB_VERSION('11.2.0.4')

      ALL_ROWS

      OUTLINE_LEAF(@"SEL$1")

      FULL(@"SEL$1" "A"@"SEL$1")

      END_OUTLINE_DATA

  */

  declare

    v_hints sys.sqlprof_attr;

    v_sqltext clob;

  begin

    select sql_fulltext into v_sqltext from v$sql where sql_id='aq03p7muwgvq5' and rownum<2;

    v_hints:=sys.sqlprof_attr(q'[FULL(@"SEL$1" "A"@"SEL$1")]');

    dbms_sqltune.import_sql_profile(v_sqltext,v_hints,'sql_full',force_match=>true,replace=>true);

  end;

  建立索引

  create index I_ind_object_id_com on a(object_id,object_name) nologging;

  查看执行计划,并没有走索引:

   Execution Plan

  ----------------------------------------------------------

  Plan hash value: 2248738933

  --------------------------------------------------------------------------

  | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

  --------------------------------------------------------------------------

  |   0 | SELECT STATEMENT  |      |     1 |    98 |   177   (1)| 00:00:01 |

  |*  1 |  TABLE ACCESS FULL| A    |     1 |    98 |   177   (1)| 00:00:01 |

  --------------------------------------------------------------------------

  Predicate Information (identified by operation id):

  ---------------------------------------------------

     1 - filter("OBJECT_ID"=3)

  Note

  -----

     - SQL profile "sql_full" used for this statement

  Statistics

  ----------------------------------------------------------

            7  recursive calls

            0  db block gets

         1254  consistent gets

         1246  physical reads

            0  redo size

         1606  bytes sent via SQL*Net to client

          519  bytes received via SQL*Net from client

            2  SQL*Net roundtrips to/from client

            0  sorts (memory)

            0  sorts (disk)

            1  rows processed

  删除profile

  begin

     dbms_sqltune.drop_sql_profile('sql_full');

     end;

  再次执行sql,找到走索引的outline

  当然你也可以用SQLT里的coe_xfr_sql_profile.sql或者create_sql_profile.sql生成sql_profile;

  这里有一点比较扯的是用完整的outline,写进去不报错,但执行计划不走sql_profile里约定的内容;

  declare

    v_hints sys.sqlprof_attr;

    v_sqltext clob;

  begin

    select sql_fulltext into v_sqltext from v$sql where sql_id='aq03p7muwgvq5' and rownum<2;

    v_hints:=sys.sqlprof_attr(

  q'[BEGIN_OUTLINE_DATA]',

  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',

  q'[OPTIMIZER_FEATURES_ENABLE('11.2.0.4')]',

  q'[DB_VERSION('11.2.0.4')],

  q'[ALL_ROWS]',

  q'[OUTLINE_LEAF(@"SEL$1")]',

  q'[FULL(@"SEL$1" "A"@"SEL$1")]',

  q'[END_OUTLINE_DATA]');

    dbms_sqltune.import_sql_profile(v_sqltext,v_hints,'sql_full',force_match=>true,replace=>true);

  end;

本文最后更新于 2023-3-21 14:47,某些文章具有时效性,若有错误或已失效,请在网站留言或联系站长:17tui@17tui.com
·END·
站长网微信号:w17tui,关注站长、创业、关注互联网人 - 互联网创业者营销服务中心

免责声明:本站部分文章和图片均来自用户投稿和网络收集,旨在传播知识,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系我们及时修正或删除。谢谢!

17站长网微信二维码

始终以前瞻性的眼光聚焦站长、创业、互联网等领域,为您提供最新最全的互联网资讯,帮助站长转型升级,为互联网创业者提供更加优质的创业信息和品牌营销服务,与站长一起进步!让互联网创业者不再孤独!

扫一扫,关注站长网微信

大家都在看

热门排行

最近更新

返回顶部