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 


 

 

 


 

 

 
 

Historical analysis of SQL execution plans

Oracle Database Tips by Donald BurlesonJanuary 9,  2015

 

SQL Plan history Analysis is not an easy chore.  As the world's most robust and complex database, Oracle offers something for everyone, and it can be confusing to optimize Oracle because of the plethora of features.

One wonderful feature of Oracle is the ability to have SQL execution plans change when the characteristics of the underlying table changes.   For shops where a table is huge one day and small the next, of shops where column distribution vary wildly, dynamic SQL is a Godsend.

However, dynamic SQL changes are not so great for stable shops where there exists one, and only one optimal execution plan for any given SQL statement.

To learn more, see my notes on identifying your SQL philosophy.

Because SQL plans will change whenever we make changes to the instance, any SQL statement will have a history of execution plans.  Here are some common acts that will change execution plans:

  • Enabling dynamic sampling

  • Table in index DDL (e.g. dropping an index)

  • Re-analyze the schema statistics (done automatically, starting in 10g)

  • Changing an optimizer parameter (optimizer_mode, optimizer_index_cost_adj)

  • Enabling parallelism

This execution plan history can be seen by running scripts against the STATSPACK (stats$sql_plan and stats$sql_plan_usage) or the AWR (dba_hist_sql_plan) tables. 

Once you have acquired the SQL_ID for a statement, you can use the built-in dbms_xplan.display_awr procedure to see all the different execution plans for the query.

The dbms_xplan.display_awr allows you to input only a SQL_ID, and Oracle will show you the of the explain plans for that SQL_ID, as recorded in the AWR. This simple query will show changes to SQL explain plan history, if you have purchased the extra-cost licenses for AWR.

  select * from TABLE(DBMS_XPLAN.DISPLAY_AWR('&sqlid'));

For more detailed scripts, and free STATSPACK script to monitor SQL execution patterns with details on historical SQL plan analysis, see my book "Oracle Tuning: The Definitive Reference".

Oracle 11g has introduced a wealth of new tools to help us "freeze" optimal SQL execution plan, so that they do not change when the data changes, tools such as the 11g SQL Performance Analyzer which uses a scientific approach to run real-world workloads and only change the SQL execution plans when they are at least 3x faster.  For complete details, see the 11g New Features book.

Also, see these notes from the Oracle CBO group on SQL plan history analysis., where they coined the term "plan regression" for changes that result in a sub-optimal execution plan.  While Oracle 11g has tools for tracking explain plans, you can still choose manual methods, gathering changes to execution plans from STATSPACK or the extra-cost AWR tables.

The following script will identify those SQL statement that have more than one execution plan in the library cache.  Note that this SQL also looks into historical SQL plans (using dba_hist_sqlstat).  This is an important report for showing the effect of DDL and statistics changes on the execution plans of SQL in a controlled, production environment.

select
   vs.sid,
   vs.sql_id,
   vs.last_call_et,
   sq.plan_hash_value
from
   v$session vs,
   v$sql     sq
where
   vs.sql_id=sq.sql_id
and
   vs.sql_child_number=sq.child_number
and
   sq.plan_hash_value not in
   (select
      ss.plan_hash_value
   from
      dba_hist_sqlstat ss
   where
      ss.sql_id=sq.sql_id) and
   0 <
      (select
           count(ss.plan_hash_value)
       from
           dba_hist_sqlstat ss
   where
      ss.sql_id=sq.sql_id);

 
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.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

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.