Oracle 12.2 优化器自适应特性(Optimizer Adaptive Features)
##12.1和12.2的变化
在12.1 中optimizer_adaptive_features 一个参数控制所有优化器自适应特性
在12.2 中oracle 引入了2个独立参数来控制oracle 的optimizer adaptive features(adaptive plans and adaptive statistics),目的应该是为了更加灵活的,独立管理新功能;
##关于optimizer adaptive features(adaptive plans and adaptive statistics
adaptive plans 和 adaptive statistics 并不是特定的优化器功能,他们是一组优化器特性的总称,adaptive plans 特性下有许多功能项,adaptive statistics特性下也有许多功能项;
oracle 12.2 默认将他们全部启用:
SQL> show parameter OPTIMIZER_ADAPTIVE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_adaptive_plans boolean TRUE
optimizer_adaptive_statistics boolean FALSE
optimizer_adaptive_plans default TRUE |
Description |
Nested loop join/Hash join selection |
The optimizer chooses between nested loops or hash joins at query runtime. |
Adaptive parallel distribution method |
The parallel distribution method is determined at runtime. |
Star transformation bitmap pruning |
Certain bitmap indexes may be removed from the SQL execution plan at runtime if selectivity is significantly poorer than the estimate. |
These features are disabled by default:
optimizer_adaptive_statistics default FALSE |
Description |
SQL plan directives |
SQL plan directives are created and used to adapt SQL execution plans. |
Statistics feedback for joins |
Cardinality from table joins is used to improve SQL execution plans. |
Performance feedback |
Improves the degree of parallelism chosen when PARALLEL_DEGREE_POLICY is set to ADAPTIVE PARALLEL_DEGREE_POLICY默认是MANUAL |
Adaptive dynamic sampling for parallel execution |
Dynamic statistics are gathered for certain parallel queries to improve cardinality estimates. The sample size is determined automatically. |
SQL Plan Directives
设置 optimizer_adaptive_statistics = FALSE 并不会禁用SQL plan directives 创建;只是不会和 dynamic statistics 一起使用来影响sql 执行计划;
Statistics Feedback
设置optimizer_adaptive_statistics=FALSE会禁用12c join statistics feedback,但是单表的cardinality feedback 仍然可用;
Adaptive Dynamic Sampling
optimizer_adaptive_statistics 这个 特性在12c 18c 中默认都是关闭的,说明oracle 也觉得这个功能不稳定,要么他只是适用于特定场景;
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
SQL> show parameter ada
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
fileio_network_adapters string
optimizer_adaptive_plans boolean TRUE
optimizer_adaptive_reporting_only boolean FALSE
optimizer_adaptive_statistics boolean FALSE
Changes to Auto Creation of Column Group Statistics
在12.1 中 SQL Plan Directives会自动触发column group statistics 收集
已创建的扩展统计信息查看:
select owner,
table_name,
extension,
extension_name
from dba_stat_extensions
where creator = 'SYSTEM'
order by owner,table_name,extension_name;
在12.2 中 extended statistics不会自动创建. (oracle 根据dba反馈要求不要自动启动,能够手动配置 )
手动启用:
EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_STAT_EXTENSIONS','ON')
Oracle 官方关于以上参数的设置选择:
Oracle 官方建议默认参数已经适用大多数情景;
Adaptive statistics features are more useful in environments where queries, data distributions and schemas are very complex;In systems like this, where query execution times are longer, it makes especially good sense for the optimizer to invest time and resources to improve the overall quality of the execution plans.
根据上面的官方描述,Adaptive statistics features 比较适合于一些olap 类业务系统,这类系统本来sql 的执行时间较长,且sql 比较复杂;优化较为麻烦;启用Adaptive statistics features 可以带来好处;其实从侧面也反应出Adaptive statistics features 启用后会有较大的性能开销;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|