Re: Performance question: Union vs OR

Tobias Downer <[email protected]> Fri, 06 May 2005 15:44:19 -0700
Newsgroups gmane.comp.db.mckoi
Message-ID <[email protected]>
Hi,

It depends on the query.  It's best avoid using a composite table 
function (UNION) unless there's no other solution.  The query planner 
will, in most cases, be able to find a better solution when using OR. 
There are some exceptions to this rule, but generally I advise using OR 
and only use UNION if there isn't another solution or if you find it 
performs better.

Toby.


M. A. Sridhar wrote:
> Hi Toby,
> 
> Can you throw some light on how the performance of the UNION operator
> compares with using an OR? I am looking for a generic recommendation on the
> circumstances under which use one or the other is preferable. Specifically,
> we can say
> 
> select <select clause> from <table list> where <condition1>
> union
> select <select clause> from <table list> where <condition2>
> 
> 
> or we can say
> 
> select <select clause> from <table list> where <condition1> or <condition2>
> 
> 
> My questions:
> - Is there any reason to prefer one form over the other? 
> - Is there any impact on performance if either of these structures is used in
> a subquery?
> 
> 
> Thanks in advance.
> 
> 
> M. A. Sridhar


---------------------------------------------------------------
Mckoi SQL Database mailing list  http://www.mckoi.com/database/
To unsubscribe, send a message to [email protected]