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

 
 Home
 E-mail Us
 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 


 

 

 


 

 

 
 

SQL where clause order can change performance

Oracle Tips by Burleson Consulting

October 26, 2009

Many people believe that the Oracle cost-based SQL optimizer does not consider the order that the Boolean predicates appear in the WHERE clause.

However, there is some evidence that this is not completely true, as evidenced by the ordered_predicates SQL hint.

The ordered_predicates hint (deprecated in 10g r2) is specified in the WHERE clause of a query and is used to specify the order in which Boolean predicates should be evaluated. In the absence of ordered_predicates (which is deprecated in Oracle 10g and beyond), Oracle uses the following steps to evaluate the order of SQL predicates:

  • Subqueries are evaluated before the outer Boolean conditions in the WHERE clause.

  • All Boolean conditions without built-in functions or subqueries are evaluated in reverse from the order they are found in the WHERE clause, with the last predicate being evaluated first.

  • Boolean predicates with built-in functions of each predicate are evaluated in increasing order of their estimated evaluation costs.

The problem is that the Oracle SQL optimizer might re-arrange the order of the where clause predicates, causing sub-optimal execution plans.

If you experiment with changing the order of predicates in the WHERE clause you will notice changes to the execution plan.

It's also been noted that Oracle follows different goals when applying predicates using I/O costing vs. CPU costing. 

When optimizing for minimizing I/O:

  •  The decision tree factors are estimated physical disk reads.

  • The computed estimated cost is the "selectivity" as expressed as the percentage of rows in the table.

  • The first predicate will be the most selective, such as to move through execution with the smallest amount of transient row sets as possible.

When optimizing to minimize computing resources: (CPU Costing)

  • The decision tree estimates the number of computing units for each operation.
  •  The optimizer than shuffles the predicates to get the smallest total estimated CPU cost.
  •  The "ordered predicates" hint (deprecated in 10gr2) will change optimizer_cost_model=io, invalidating CPU costing.

In sum, while the order of WHERE clause predicates should not make a difference, there is evidence that the order of WHERE clause predicates makes a difference.

Also note that transitive closure in the WHERE clause effects performance.

 

If you like Oracle tuning, you may enjoy my new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & 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 Excel
 
Oracle performance tuning software 
 

 

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 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.