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 


 

 

 


 

 

 

 
 

Optimizer costs don't match SQL execution performance

Oracle Database Tips by Donald Burleson

Question:  I am tuning an Oracle SQL query and I've noted that the costs don't match the execution speed and SQL where the optimizer shows a lower cost actually take more time to execute.  I want to know why in second case the cost is less but time taken to execute the query is more?

Answer: It's important to note that the cost figures that are displayed in an execution plan are not described in any Oracle documentation, and it's been demonstrated that the plan with the lowest ?cost? number is not always the plan chosen by the optimizer.  Further, the ?cost? figures do not always indicate the ?best:? execution plan for a query, given the divergent optimizer goals of first_rows (optimizer for response time) and all_rows (optimize for minimizing computing resources).

In general, the lower the CBO-calculated cost, the faster the query will run, but we have to remember that the costs used by the CBO are only estimates, and the numbers are based on metadata statistics collected by dbms_stats.  The cost based optimizer (CBO) creates these estimates based on many variables:

  • system statistics - Workload statistics have an impact of the CBO cost estimates.
     
  • costing - You can have the CBO costs based on estimated I/O costs or estimated CPU costs.
     
  • object statistics - The table and index analyze with dbms_stats.
     
  • object histograms - Histograms are used to guess the cardinality of result set sizes.
     
  • CBO parms - settings for important CBO parameters (hash_area_size, db_file_multiblock_read_count, optimizer_index_caching, optimizer_index_cost_adj, &c)

Remember, if you have sub-optimal statistics, the CBO can misjudge the costs.  The most common causes for inaccurate CBO costing estimates may include:

  • Bad table join order - sub-optimal table join order can be caused by missing histograms.
     
  • Inaccurate I/O estimates - Oracle uses the estimate of single block read time which can be inaccurate in system statistics (i.e. dbms_stats.gather_system_stats) are missing.
     
  • Buffer caching estimates - If you don't set optimizer_index_caching or if the contents of your data buffers vary greatly, the optimizer can mis-estimate the I/O costs for a query optimization.

You might also have an issue with a SQL optimizer bug, see how to display optimizer features and bug fixes by release.

References on CBO costing:

See my related notes on CBO cost estimates:


 
If you like Oracle tuning, see the book "Oracle Tuning: The Definitive Reference", with 950 pages of tuning tips and scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


 

 

��  
 
 
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.