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 


 

 

 


 

 

   

Sheila Jenkins

Oracle News Headlines

 


Chris Date Challenges Oracle Optimizer Subquery
Re-write
September 14, 2004

Jonathan Gennick, noted Oracle expert and author recently published a great article on Oracle SQL sub-query behavior titled "subquery Madness":
 
http://five.pairlist.net/pipermail/oracle-article/2004/000012.html
 
In response, Chris Date, founder of the relational database model, published a response that notes an important feature of subquery re-write features of the Oracle cost-based SQL optimizer.
 
 
These articles provide unparalleled insights into the inner workings of Oracle's cost-based optimizer for subquery rewriting.
 
Date notes:

Now suppose we use the original query as a subquery within the FROM clause of another query: 

SELECT *
FROM ( SELECT FLAG, TO_NUMBER ( NUM ) NUM
       FROM   SUBTEST
       WHERE  FLAG = 'N' )
WHERE  NUM > 0 ;

According to Gennick, this query fails with the following error message: 

ERROR:
ORA-01722: invalid number

Gennick suggests in his paper that the failure occurs because the outer query attempts to evaluate the condition NUM > 0 on one of the nonnumeric values in column NUM.  To quote:  "[The] optimizer is free to test ... rows against [the] NUM > 0 predicate first, if that's deemed more efficient." 

As Gennick subsequently points out, however, the foregoing explanation cannot be correct, because the condition NUM > 0 involves a type error (one that should be caught at compile time, moreover)--NUM is of type character string and 0 is of type numeric.  What has really happened is that the optimizer has rewritten the original query as follows: 

SELECT FLAG, TO_NUMBER ( NUM ) NUM
FROM   SUBTEST
WHERE  TO_NUMBER ( NUM ) > 0
AND    FLAG = 'N' ;

Now it's clear that the failure occurs as soon as the system tries (in the WHERE clause) to convert some nonnumeric NUM value--say 'pqr'--to a number.  The question is, then:  Is this rewriting on the part of the optimizer valid?  The short answer is no. 

 

 

 

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

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

Remote Emergency Support provided by Conversational