General subselect question

Поиск
Список
Период
Сортировка
Искать

General subselect question

От:
Tim Hart <tjhart@me.com>
Дата:
In the general case, is a subselect that uses union less performant  
than a union?

I have a query that looks something like this:

select 
from   table1,
           table2,
           table3
where 
union
select 
from    table1,
            table2,
            table3 ref1,
            table3 ref2
where 

I realized today that I could convert the query to

select 
from    table1,
            table2,
            ( select 
               from   table3
               where 
               union
               select 
               from    table3 ref1,
                          table3 ref2
               where   )
where    

For my specific case, I'll use EXPLAIN   to determine the performance  
difference. I'll weigh the performance benefits with the maintenance  
benefits ( less duplication of code for me on the second case) and  
decide (assuming I'm still motivated on Friday ;) ).

But in the general case, do I have to pay special attention with  
unions in subselects?

Tim Hart
615-713-9956 :cell
timothyjhart :Y!
tjhart@me.com :AIM
FAQ