This depend only on reduction scale.If your particullar queries have many 
duplicates e.g 90% or more, than separate distinct can be better from resource 
POV. But if it is opposite, then eliminate particular distinct operations can 
have huge performance boost.Regards,Karol Bieniaszewski
-------- Oryginalna wiadomość --------Od: "Kjell Rilbe 
kjell.ri...@marknadsinformation.se [firebird-support]" 
<firebird-support@yahoogroups.com> Data: 02.01.2020  21:49  (GMT+01:00) Do: 
firebird-support@yahoogroups.com Temat: [firebird-support] Union with or 
without distinct in the separate queries? 
 



  


    
      
      
      Hi,



Not important, just got curious: Consider a query like this:



select c1 from t1

union select c1 from t2;



This will eliminate all duplicates, since I didn't specify "union all". 

But would this be more or less efficient than (or the same as) this:



select distinct c1 from t1

union select distinct c1 from t2;



I'm thinking that the latter will reduce the number of records to 

consider "as early as possible" any may reduce resource usage that way. 

On the other hand it would involve three "distinct" operations rather 

than a single one... So maybe the answer is that it depends on the data, 

which indices are available and applicable, and may differ from case to 

case? Or perhaps the query engine recognizes that the two queries are 

logically equivalent and executes them identically?



Regards,

Kjell




[Non-text portions of this message have been removed]



    
     

    
    


  • [firebir... Kjell Rilbe kjell.ri...@marknadsinformation.se [firebird-support]
    • RE:... liviuslivius liviusliv...@poczta.onet.pl [firebird-support]

Reply via email to