[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数据库的通病.

时间: 2024-10-23 18:23:19

[20170625]12c Extended statistics.txt的相关文章

0429建立Extended Statistics函数索引问题

[20160429]建立Extended Statistics 和函数索引问题.txt --11G支持相关数据的统计分析,比如如果两个字段存在相关性通过分析,能够得到更加良好的统计信息,以及生成好的执行计划. --但是如果结合函数索引呢?通过一个简单的例子来说明: --前次做的测试: http://blog.itpub.net/267265/viewspace-2089119/ 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                  

0427建立Extended Statistics函数索引问题

[20160427]建立Extended Statistics 和函数索引问题.txt --11G支持相关数据的统计分析,比如如果两个字段存在相关性通过分析,能够得到更加良好的统计信息,以及生成好的执行计划. --但是如果结合函数索引呢?通过一个简单的例子来说明: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ ---

[20130809]12c Clustering Factor.txt

[20130809]12c Clustering Factor.txt 以前在11G以前,如果使用assm,表的CF经常会很大,即使你插入的像顺序号这样的字段,由于多个会话同时操作,插入的数据分布的不同的块中,以顺序号为索引的CF也会变得很大,甚至接近记录的数量.这个在<基于成本的优化>里面也有介绍. 但是在12g可以设置一个参数改善这种情况,做一些测试看看. 参考了Richard Foote大师的blog:http://richardfoote.wordpress.com/2013/05/0

[20160910]12c sqlldr express.txt

[20160910]12c sqlldr express.txt --Oracle 12c introduces Sql*Loader Express features, which allow users to run sqlldr with minimum configuration.   --通过例子来说明: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION        BANNER                 

[2016026]12c lateral语法.txt

[2016026]12c lateral语法.txt 12c 支持一种LATERAL的写法,例子: SELECT e1.*, e3.avg_sal   FROM scott.emp e1       ,LATERAL (SELECT AVG (e2.sal) avg_sal                   FROM scott.emp e2                  WHERE e1.deptno != e2.deptno) e3; -- 显示emp每行,同时显示其它不是本部门的平均

[20130721]ORACLE 12C Invisible Columns.txt

[20130721]ORACLE 12C Invisible Columns.txt 在ORACLE 12C中有了Invisible Columns的概念,就是在表中真实的存在该列,但是通过设置Invisible可以实现不显示该列.自己测试看看. SQL> select banner from v$version ; BANNER -------------------------------------------------------------------------------- Or

[20131221]12c 优化 bug.txt

[20131221]12c 优化 bug.txt http://connormcdonald.wordpress.com/2013/12/20/the-challenge-of-optimization/ --仅仅自己重复测试看看! @ver BANNER                                                                               CON_ID ------------------------------------

[20130916]12c Indexing Extended Data Types and index.txt

[20130916]12c Indexing Extended Data Types and index.txt http://richardfoote.wordpress.com/2013/09/12/12c-indexing-extended-data-types-part-i-a-big-hurt/ 参考以上链接,做一些测试: 1.测试环境: SCOTT@test01p> @ver BANNER                                                

[20130918]12C表统计信息的在线收集.txt

[20130918]12C表统计信息的在线收集.txt 在12c以前,如果使用ctas建立表,并不会自动收集表的统计信息,12c开始CTAS和IAS操作会收集统计信息.但是不收集直方图信息.以及索引统计. 摘要:twp-bp-for-stats-gather-12c-1967354.pdfBest Practices for Gathering Optimizer Statistics with Oracle Database 12c P16-17页: Online statistics gat