Saturday, August 4, 2012

Today I learnt something new in SQL Queries.. 
Thot I could share with you ppl!

I was running 
query a (select col1 from table1)>> execution time 3 secs
query b (select col1 from table2)>> execution time 5 secs
query a intersect query b 
(select col1 from table1 intersect select col1 from table2)>> execution time 16 mins!

Lot of technicalities and reasons are there for this behavior... but quick fix is as follows
select col1 from table1 where rownum>0
select col1 from table2 where rownum>0 >> execution time 6 secs!


Naveed Ayub said...

Very Nice article, thank u

Micro Paywall said...

Sounds like the intersect wasn't using hashing to generate the intersection. Probably better to use an inner join in this case.