zoukankan      html  css  js  c++  java
  • [20170625]12c Extended statistics.txt

    [20170625]12c Extended statistics.txt

    --//别人的系统12c,awr报表出现大量调用执行如下sql语句.
    select default$ from col$ where rowid=:1;

    --//google看了一下,问题出在Extended statistics的问题,12c 会自动收集扩展统计信息.找到如下链接:
    --//https://blog.dbi-services.com/sql-plan-directives-strike-again/

    1.环境:
    SCOTT@test01p> @ ver1
    PORT_STRING                    VERSION        BANNER                                                                               CON_ID
    ------------------------------ -------------- -------------------------------------------------------------------------------- ----------
    IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

    --//特别在应用不使用绑定变量的情况下,12c这个问题会更严重,据说12.2已经解决这个问题.

    select default$ from col$ where rowid=:1;
    --//sql_id=''47r1y8yn34jmj'.

    --//仅仅记录作者的结论:
    --//https://blog.dbi-services.com/sql-plan-directives-strike-again/

    Conclusion

    In that case, the solution is both to change the application to use bind variable (it's perl, very easy) and apply the
    patch.

    I'm sharing that because it's a good illustration of what side effects can do, as well as a good example of methodical
    troubleshooting. When you know the reason without blind guesses, you can address the root cause. If you don't, the risk
    is that you add even more side effects.

    By the way, please use bind variables…

    --//我也google,也许设置"_optimizer_enable_extended_stats"=FALSE,也可以.不过这样估计就不能使用建立与使用这样的统计.

    alter system set "_optimizer_enable_extended_stats"=FALSE scope=both;

    SYS@test> @ hide _optimizer_enable_extended_stats
    NAME                             DESCRIPTION                                        DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE
    -------------------------------- -------------------------------------------------- ------------- ------------- ------------
    _optimizer_enable_extended_stats use extended statistics for selectivity estimation TRUE          TRUE          TRUE

    --//再或者设置如下,这也是我使用的方法:
    alter session set cursor_sharing="force" scope=both;

    --//删除不需要的扩展统计,例子:
    exec dbms_stats.drop_extended_stats(ownname => 'SCOTT',tabname => 'EMP',extension => '("ENAME","JOB")');

    2.自己手工建立删除看看.
    SCOTT@test01p> select DBMS_STATS.create_extended_stats(ownname => 'SCOTT',tabname => 'EMP',extension =>'("ENAME","DEPTNO")') c30 from dual ;
    C30
    ------------------------------
    SYS_STUU2WA2Z3E__3QS4G4E5M$QPA
    --//注不能exec 来执行.

    SCOTT@test01p> column EXTENSION_NAME format a30
    SCOTT@test01p> select * from dba_stat_extensions where owner='SCOTT' ;
    OWNER      TABLE_NAME EXTENSION_NAME                 EXTENSION                CREATOR DRO
    ---------- ---------- ------------------------------ ------------------------ ------- ---
    SCOTT      EMP        SYS_STUU2WA2Z3E__3QS4G4E5M$QPA ("ENAME","DEPTNO")       USER    YES
               EMP        SYS_NC00009$                   (STANDARD_HASH("ENAME")) SYSTEM  NO

    SCOTT@test01p> exec dbms_stats.drop_extended_stats(ownname => 'SCOTT',tabname => 'EMP',extension => '("ENAME","DEPTNO")');
    PL/SQL procedure successfully completed.

    SCOTT@test01p> select * from dba_stat_extensions where owner='SCOTT' ;
    OWNER      TABLE_NAME EXTENSION_NAME                 EXTENSION                CREATOR DRO
    ---------- ---------- ------------------------------ ------------------------ ------- ---
    SCOTT      EMP        SYS_NC00009$                   (STANDARD_HASH("ENAME")) SYSTEM  NO

    --//可以发现已经删除.
    --//补充:https://smarttechways.com/2017/01/06/extended-stats-in-oracle/

    SQL plan directives can be used by Oracle to determine if extended statistics specifically column groups, are missing
    and would resolve the cardinality misestimates. After a SQL directive is used the optimizer decides if the cardinality
    not be estimate could be resolved with a column group. If so, the database can automatically create that column group
    the next time statistics are gathered on the appropriate table.

    This step is "always on" in Oracle Database 12c Release 1, but from Oracle Database 12c Release 2, it is controlled by
    the DBMS_STATS preference AUTO_STAT_EXTENSIONS. Note that the default is OFF, so to enable automatic column group
    creation the following.

    EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_STAT_EXTENSIONS', 'ON');

    --//我的环境没有这个参数.

    总结:
    1.我个人的建议不要过早的使用XX.1的版本,这样就是人家试验品.
    2.国内应用大量不使用绑定变量,这个也是国内使用oracle数据库的通病.

  • 相关阅读:
    mq/mysql/redis/nginx常见服务&工具安装
    中断——中断描述符表的定义和初始化(二) (基于3.16-rc4)
    中断——中断描述符表的定义和初始化(一) (基于3.16-rc4)
    linux内核中与进程相关的数据结构(基于linux3.16-rc4)
    内核链表的应用
    ubuntu下做柯老师lab19-lab20实验问题总结
    在ns2.35中添加myevalvid框架
    在ns2.35下完成柯老师lab18实验
    windows编程socket问题
    如何高效利用GitHub
  • 原文地址:https://www.cnblogs.com/lfree/p/7078983.html
Copyright © 2011-2022 走看看