Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle adaptive SQL execution plan tips

Oracle Database Tips by Donald BurlesonOctober 16, 2015


Question:  How do the Oracle 12c adaptive execution plans work?

Answer:  The Oracle12c adaptive execution plans are a add-on to Oracle dynamic sampling, a new feature of dynamic statistics.

IMPORTANT NOTE: Oracle dynamic sampling has been re-named to Oracle adaptive statistics  in Oracle 12c.  Also see Oracle 12c adaptive optimization of SQL.

Oracle is striving to get over an ongoing issue with always having enough detail in the metadata to always choose the "best" execution plan, and Oracle is now working towards an adaptive, "self-learning" optimizer. In 12c and beyond, you can tell when Oracle has changed the plan because of adaptive plans:

Note
-----
- this is an adaptive plan

In this new approach, "real-time" statistics collection is done at query execution time, and the optimizer postpones the join decision until it has sampled the characteristics of the tables!

At run time, the Oracle optimizer begins a nested loops join, and buffers the data until it has a chance to see whether a hash join might be a faster join technique.  If so, Oracle will abandon the bested loops join and change it into a hash join, all during query execution.

This added run-time flexibility has the option of changing a tables join methods between a hash join to a nested loops join, well after the original plan was generated!  Join statistics are now monitored for executing SQL statements and a new v$sql column is_reoptimizable has been added to indicate when a query will benefit from dynamic statistics.

This process imposes a "minor hit: to performance directing the first execution of the SQL statement, but upon re-execution of the SQL statement, the execution plan will remain as determined originally, and that step of optimization is passed-through.

This funky new functionality is controlled by a parameter optimizer_adaptive_reporting_only=false, and it can be disabled with optimizer_adaptive_reporting_only=true.

In a sense, the dynamic sampling feature has been replaced by a dynamic statistics feature.  You can see information about these last-minute changes to SQL execution plans with the dbms_xplan package, using the format of "+all_dyn_plan +adaptive".  Oracle also introduces SQL plan directives, and there is a new DBMS package dbms_spd to manage these sub-components of an execution plan.

One of the most common "problems" with a sub-optimal execution plan is when the optimizer cannot guess the proper cardinality for a table join result or a filtering condition.  The 12c optimizer has been enhanced to "peek" into the query results to see if the query cardinality estimate corresponds to the initial guess from the optimizer.  If the optimizer notices that he came up with a sub-optimal SQL execution plan, the optimizer will:

1 - Store the "real" stats in the data dictionary as "adaptive statistics".

2 - Take the change into consideration for later queries, using the "real" cardinality in lieu of the cardinality estimate.

3 - Note a new step called a "STATISTICS COLLECTOR" in a tkprof (SQL Trace).

4 - The resulting stats are cached as shared dynamic stats specific for the statement, including the bind values. This information can be used by any session using the same SQL query. 

Oracle has implemented this new adaptive statistics collection within Oracle dynamic sampling, such that whenever the existing statistics (or 12c "extended statistics") fail to generate an optimal plan, the output from the dynamic sampling will be made persistent within the data dictionary.

Learning from your mistakes

One of the reasons that adaptive optimizer statistics are so exciting is that the optimizer has been re-written to peek-ahead and learn from its mistakes.  Properly implemented, adaptive optimizer statistics can be a Godsend for the optimizer, allowing for complex metadata relationships to be documented, all toward the goal of always getting the "best" execution  plan for any SQL query.


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster