Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> MINUS VS NOT IN

MINUS VS NOT IN

From: Peter Hazelton <peterhazelton_at_hotmail.com>
Date: Thu, 08 Feb 2001 13:20:38 -0800
Message-ID: <F001.002AFA44.20010208130314@fatcity.com>

Hello all.

I read a question concerning the use of the MINUS function earlier and I had not heard of it before today. After some experimenting with it, I was quite amazed at the speed of this function compared to using NOT IN.

Considering the following:

Query One

select distinct icons from inpatient
minus select distinct icons from ptca;

Query 2

select distinct icons from inpatient
where icons NOT IN(select distinct icons from ptca)

Query number one began to run in about 5 seconds whereas query 2 took forever to run. My question is why is the MINUS so much faster?

My understanding of the NOT IN is that it probably builds the record set in the second part of the SQL query each time it comes to a new icons number in the first part of the query. Therefore, if there are one thousand records to be searched, it probably builds the record set one thousand times. Is this correct? If so, how does the MINUS function build and compare the record set?

And finally, where do I get these wonderful little tidbits? Would a SQL tuning book exist that might talk about the strengths and limitations of different functions? I really appreciate your time and input.

Petre Hazelton
Halifax, Nova Scotia CANADA



Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Peter Hazelton
  INET: peterhazelton_at_hotmail.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Thu Feb 08 2001 - 15:20:38 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US