[20170625]12c Extended statistics.txt

简介: [20170625]12c Extended statistics.txt --//别人的系统12c,awr报表出现大量调用执行如下sql语句. select default$ from col$ where rowid=:1; --//google看了一下,问题出在Extended statistics的问题,12c 会自动收集扩展统计信息.

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

目录
相关文章
|
7月前
Manage Audit File Directory Growth with cron (Doc ID 1298957.1)
Manage Audit File Directory Growth with cron (Doc ID 1298957.1)
39 3
|
关系型数据库 测试技术 Oracle
[20180102]statistics_level=BASIC.txt
[20180102]statistics_level=BASIC.txt --//一个测试环境不知道谁设置statistics_level=BASIC,导致重启出现错误,自己在测试环境模拟看看: SYS@book> create pfile='/tmp/@.
1255 0
|
测试技术 关系型数据库 Oracle
[20171106]DBMS_UTILITY.GET_TIME().txt
[20171106]DBMS_UTILITY.GET_TIME().txt --//有时候测试某个脚本运行时间,经常在这之前之后调用这个函数.今天奇怪的发现显示竟然是负数,感觉很奇怪做一个探究.
1032 0
|
SQL 关系型数据库 Oracle
plsql dev中Dynamic Performance Tables not accessible分析解决(转)
使用plsql dev的朋友多遇到过类此如下面的提示: Dynamic Performance Tables not accessible, Automatic Statistics Disabled for this session You can disable statistic...
1191 0
|
SQL 索引 Perl
[20150228]DBMS_STATS Tracing.txt
[20150228]DBMS_STATS Tracing.txt --这个是很久的链接,可以跟踪dbms_stats的操作过程,自己测试看看。 http://www.
946 0
|
SQL Oracle 关系型数据库
[20141006]analyze与dbms_stats.txt
[20141006]analyze与dbms_stats.txt --别人问一个奇怪的问题,如何知道表使用analyze分析的还是使用dbms_stats分析的.
822 0
|
SQL Oracle 关系型数据库
[20140108]12c新特性_Statistics Feedback.txt
[20140108]12c新特性_Statistics Feedback.txt 摘自:Apress.Pro.Oracle.SQL.2nd.Edition.Nov.
755 0