Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 25 Feb 2005 @ 08:33:57 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: Which is faster
 
From:   Dieter Noeth

Narayan Murthy wrote:

  Is the query with an AND faster when compared to an INTERCEPT query. And similarly is OR faster when compared to a UNION query.  


If you rewrite intersect/union with and/or it's usually more efficient:

- two accesses to the base table vs. one access

- distinct vs. no distinct


I usually recommend union/intersect/except only if the data is from different tables.

On some rare cases when set operations may be more efficient, but you have to EXPLAIN...

There's only one case when union is always better, a OR-ed join condition:

     select
     from t1 join t2
     on t1.col1 = t2.col1
     OR t1.col1 = t2.col2

This will *always* result in a product join, so rewrite as

     select
     from t1 join t2
     on t1.col1 = t2.col1
     union [all]
     select
     from t1 join t2
     on t1.col1 = t2.col2


Dieter



     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023