SQL - query inside NOT IN takes longer than the complete query ??

Posted by Aleksandar Tomic on Stack Overflow See other posts from Stack Overflow or by Aleksandar Tomic
Published on 2011-01-05T13:20:24Z Indexed on 2011/01/05 13:54 UTC
Read the original article Hit count: 385

Filed under:
|

Hi every1,

I'm using NOT IN inside my SQL query.

For example:

select columnA 
from table1
where columnA not in (
select columnB
from table2)

How is it possible that this part of the query

select columnB
from table2

takes 30sec to complete, but the whole query above takes 0.1sec to complete?? Shouldn't the complete query take 30sec + ?

BTW, both queries return valid results.

Thanks!

Answers to Comments

Is it because the second query hasn't actually completed but has only returned back the first 'x' rows (out of a very large table?)

No, the query is completed after 30 seconds, not to many rows returned (eg. 50).

But @Aleksandar wondered why the question congaing the performance killer was so fast.

my point exactly

Also how long does select distinct columnB from table2 take to execute?

actually, the original query is "select distinct...

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle