RE: minus vs. where not exists, vs. where not in

2003-09-22 Thread Sinardy Xing
well superman is poorer than batman


-Original Message-
Sent: 22 September 2003 13:45
To: Multiple recipients of list ORACLE-L



Yeah, Superman had Super powers.  Batman just relied on a bunch of gadgets.

Of course my original post was implying the classic "it depends".  There
are some scenario's where a specific approach is faster than the other and
there are some scenario's where it doesn't matter because oracle can
rewrite the query effectively anyway.  What does matter - "If in doubt test
it out".



   
   
  "Sinardy Xing"   
   
  <[EMAIL PROTECTED]To:   Multiple recipients of list 
ORACLE-L <[EMAIL PROTECTED]>  
  omsvc.com>   cc: 
   
              Sent by:             Subject:  RE: minus vs. where not 
exists, vs. where not in 
  [EMAIL PROTECTED]
   
  .com 
   
   
   
   
   
  22/09/2003 15:29 
   
  Please respond to
   
  ORACLE-L 
   
   
   
   
   




I think Superman is stroger than Batman

-Original Message-
Sent: 22 September 2003 08:30
To: Multiple recipients of list ORACLE-L


I'm not sure that there is a good answer to that question. The question
sounds like the dilemma: who's stronger, Batman or Superman?
Unfortunately, superheroes do not exist, so we cannot have a real life
comparison. It is exactly the same with not exists vs. minus. Comparisons
make
sense only within a real life application in a real configuration, that is
why both mechanisms are provided. Sort_area_size does influence
performance,
unless memory is slow, system is swapping or something else.
In the world of superheroes, my favorite is Alice and her "fist of death".

On 2003.09.21 19:54, Mark Richard wrote:
>
> I don't have any scientific proof but I imagine the sort_area_size could
be
> different between "not exists" and "minus".  When doing "minus" the
entire
> select string would have to be compared for equality, which could be very
> large depending on your string.
>
> Minus is probably an easier way (at least from a coding perspective) of
> comparing every column in a table, or incorporating complexity in the
> select statement.
>
> Having said that.  Each statement has it's pros and cons and I guess it
> depends on the volume of the various queries, etc.  For example, if the
> have table A with 5 rows and table B with 100 rows executing "select
> a.field from a where not exists (select 1 from b where b.field = a.field)
> will result in 5 quick searches (assuming b.field is indexed) whereas
> "select a.field from a where a.field not in (select b.field from b)" will
> result in a full index read of b, as would "select a.field from a minus
> select b.field from b".  Obviously different queries and different
volumes
> will tip the scales in different directions.
>
> Regards,
>   Mark.
>
>
>
>
>
>   "Ryan"
>
>   <[EMAIL PROTECTED]To:   Multiple
recipients
> of list ORACLE-L <[EMAIL PROTECTED]>
>   >cc:
>
>   Sent by: Subject:  minus vs. where
not
> exists, vs. where not in
>   [EMAIL PROTECTED]
>
>   .com
>
>
>
>
>
>

RE: minus vs. where not exists, vs. where not in

2003-09-21 Thread Mark Richard

Yeah, Superman had Super powers.  Batman just relied on a bunch of gadgets.

Of course my original post was implying the classic "it depends".  There
are some scenario's where a specific approach is faster than the other and
there are some scenario's where it doesn't matter because oracle can
rewrite the query effectively anyway.  What does matter - "If in doubt test
it out".



   
   
  "Sinardy Xing"   
   
  <[EMAIL PROTECTED]To:   Multiple recipients of list 
ORACLE-L <[EMAIL PROTECTED]>  
  omsvc.com>   cc: 
   
              Sent by:             Subject:  RE: minus vs. where not 
exists, vs. where not in 
  [EMAIL PROTECTED]
   
  .com 
   
   
   
   
   
  22/09/2003 15:29 
   
  Please respond to
   
  ORACLE-L 
   
   
   
   
   




I think Superman is stroger than Batman

-Original Message-
Sent: 22 September 2003 08:30
To: Multiple recipients of list ORACLE-L


I'm not sure that there is a good answer to that question. The question
sounds like the dilemma: who's stronger, Batman or Superman?
Unfortunately, superheroes do not exist, so we cannot have a real life
comparison. It is exactly the same with not exists vs. minus. Comparisons
make
sense only within a real life application in a real configuration, that is
why both mechanisms are provided. Sort_area_size does influence
performance,
unless memory is slow, system is swapping or something else.
In the world of superheroes, my favorite is Alice and her "fist of death".

On 2003.09.21 19:54, Mark Richard wrote:
>
> I don't have any scientific proof but I imagine the sort_area_size could
be
> different between "not exists" and "minus".  When doing "minus" the
entire
> select string would have to be compared for equality, which could be very
> large depending on your string.
>
> Minus is probably an easier way (at least from a coding perspective) of
> comparing every column in a table, or incorporating complexity in the
> select statement.
>
> Having said that.  Each statement has it's pros and cons and I guess it
> depends on the volume of the various queries, etc.  For example, if the
> have table A with 5 rows and table B with 100 rows executing "select
> a.field from a where not exists (select 1 from b where b.field = a.field)
> will result in 5 quick searches (assuming b.field is indexed) whereas
> "select a.field from a where a.field not in (select b.field from b)" will
> result in a full index read of b, as would "select a.field from a minus
> select b.field from b".  Obviously different queries and different
volumes
> will tip the scales in different directions.
>
> Regards,
>   Mark.
>
>
>
>
>
>   "Ryan"
>
>   <[EMAIL PROTECTED]To:   Multiple
recipients
> of list ORACLE-L <[EMAIL PROTECTED]>
>   >cc:
>
>   Sent by: Subject:  minus vs. where
not
> exists, vs. where not in
>   [EMAIL PROTECTED]
>
>   .com
>
>
>
>
>
>   22/09/2003 03:59
>
>   Please respond to
>
>   ORACLE-L
>
>
&g

RE: minus vs. where not exists, vs. where not in

2003-09-21 Thread Sinardy Xing
I think Superman is stroger than Batman

-Original Message-
Sent: 22 September 2003 08:30
To: Multiple recipients of list ORACLE-L


I'm not sure that there is a good answer to that question. The question
sounds like the dilemma: who's stronger, Batman or Superman?
Unfortunately, superheroes do not exist, so we cannot have a real life  
comparison. It is exactly the same with not exists vs. minus. Comparisons make  
sense only within a real life application in a real configuration, that is
why both mechanisms are provided. Sort_area_size does influence performance,
unless memory is slow, system is swapping or something else.
In the world of superheroes, my favorite is Alice and her "fist of death".

On 2003.09.21 19:54, Mark Richard wrote:
> 
> I don't have any scientific proof but I imagine the sort_area_size could be
> different between "not exists" and "minus".  When doing "minus" the entire
> select string would have to be compared for equality, which could be very
> large depending on your string.
> 
> Minus is probably an easier way (at least from a coding perspective) of
> comparing every column in a table, or incorporating complexity in the
> select statement.
> 
> Having said that.  Each statement has it's pros and cons and I guess it
> depends on the volume of the various queries, etc.  For example, if the
> have table A with 5 rows and table B with 100 rows executing "select
> a.field from a where not exists (select 1 from b where b.field = a.field)
> will result in 5 quick searches (assuming b.field is indexed) whereas
> "select a.field from a where a.field not in (select b.field from b)" will
> result in a full index read of b, as would "select a.field from a minus
> select b.field from b".  Obviously different queries and different volumes
> will tip the scales in different directions.
> 
> Regards,
>   Mark.
> 
> 
> 
> 
> 
>   "Ryan"
> 
>   <[EMAIL PROTECTED]To:   Multiple recipients
> of list ORACLE-L <[EMAIL PROTECTED]>
>   >cc:
> 
>   Sent by: Subject:  minus vs. where not
> exists, vs. where not in
>   [EMAIL PROTECTED]
> 
>   .com
> 
> 
> 
> 
> 
>   22/09/2003 03:59
> 
>   Please respond to
> 
>   ORACLE-L
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Do any of you have any cases when minus is superior in performance? Ive
> found 'not in' with a hash_aj to be the best option if the sub-query is
> significantly less 'costly' then the outer query. I dont mean cost in terms
> of the Explain Plan, I mean the work Oracle has to do to find a result set.
> It also depends on a proper hash_area_size
> 
> I find 'where not exists' to be best if the subquery is relatively close in
> cost to the outer query. Yes I know you cant make broad generalizations,
> but there has to be some 'narrow' generalizations you can make. Such as
> certain cases, etc...
> 
> what have you seen? There seems to be very little work in this area in the
> literature.
> 
> Does 'where not exist' need more or less sort_area_size space than minus?
> 
> 
> << 
> >>
>Privileged/Confidential information may be contained in this message.
>   If you are not the addressee indicated in this message
>(or responsible for delivery of the message to such person),
> you may not copy or deliver this message to anyone.
> In such case, you should destroy this message and kindly notify the sender
>by reply e-mail or by telephone on (61 3) 9612-6999.
>Please advise immediately if you or your employer does not consent to
> Internet e-mail for messages of this kind.
> Opinions, conclusions and other information in this message
>   that do not relate to the official business of
>  Transurban City Link Ltd
>  shall be understood as neither given nor endorsed by it.
> <<< 
> >
> 
> 
> 
> 
> << 
> >>
> Privileged/Confidential information may be contained in this message.
> If you are not the addressee indicated in this message (or responsible for
> delivery of the message to such person), you may not copy or deliver this
> message to anyone.
> In such a case, you should destroy this message and kindly notify the sender
> by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
> Please advise immediately if you or your employer does not consent to
> Internet e-mail for messages of this kind.
> Opinions, conclusions and other information in this message that do not
> relate to the official business of Transurban Infrastructure Developments
> Limi

Re: minus vs. where not exists, vs. where not in

2003-09-21 Thread Mladen Gogala
I'm not sure that there is a good answer to that question. The question
sounds like the dilemma: who's stronger, Batman or Superman?
Unfortunately, superheroes do not exist, so we cannot have a real life  
comparison. It is exactly the same with not exists vs. minus. Comparisons make  
sense only within a real life application in a real configuration, that is
why both mechanisms are provided. Sort_area_size does influence performance,
unless memory is slow, system is swapping or something else.
In the world of superheroes, my favorite is Alice and her "fist of death".

On 2003.09.21 19:54, Mark Richard wrote:
I don't have any scientific proof but I imagine the sort_area_size could be
different between "not exists" and "minus".  When doing "minus" the entire
select string would have to be compared for equality, which could be very
large depending on your string.
Minus is probably an easier way (at least from a coding perspective) of
comparing every column in a table, or incorporating complexity in the
select statement.
Having said that.  Each statement has it's pros and cons and I guess it
depends on the volume of the various queries, etc.  For example, if the
have table A with 5 rows and table B with 100 rows executing "select
a.field from a where not exists (select 1 from b where b.field = a.field)
will result in 5 quick searches (assuming b.field is indexed) whereas
"select a.field from a where a.field not in (select b.field from b)" will
result in a full index read of b, as would "select a.field from a minus
select b.field from b".  Obviously different queries and different volumes
will tip the scales in different directions.
Regards,
  Mark.




  "Ryan"

  <[EMAIL PROTECTED]To:   Multiple recipients
of list ORACLE-L <[EMAIL PROTECTED]>
  >cc:
  Sent by: Subject:  minus vs. where not
exists, vs. where not in
  [EMAIL PROTECTED]
  .com





  22/09/2003 03:59

  Please respond to

  ORACLE-L









Do any of you have any cases when minus is superior in performance? Ive
found 'not in' with a hash_aj to be the best option if the sub-query is
significantly less 'costly' then the outer query. I dont mean cost in terms
of the Explain Plan, I mean the work Oracle has to do to find a result set.
It also depends on a proper hash_area_size
I find 'where not exists' to be best if the subquery is relatively close in
cost to the outer query. Yes I know you cant make broad generalizations,
but there has to be some 'narrow' generalizations you can make. Such as
certain cases, etc...
what have you seen? There seems to be very little work in this area in the
literature.
Does 'where not exist' need more or less sort_area_size space than minus?

<< 
>>
   Privileged/Confidential information may be contained in this message.
  If you are not the addressee indicated in this message
   (or responsible for delivery of the message to such person),
you may not copy or deliver this message to anyone.
In such case, you should destroy this message and kindly notify the sender
   by reply e-mail or by telephone on (61 3) 9612-6999.
   Please advise immediately if you or your employer does not consent to
Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message
  that do not relate to the official business of
 Transurban City Link Ltd
 shall be understood as neither given nor endorsed by it.
<<< 
>



<< 
>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible for
delivery of the message to such person), you may not copy or deliver this
message to anyone.
In such a case, you should destroy this message and kindly notify the sender
by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
Please advise immediately if you or your employer does not consent to
Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message that do not
relate to the official business of Transurban Infrastructure Developments
Limited and CityLink Melbourne Limited shall be understood as neither given
nor endorsed by them.
<< 
>>

--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author: Mark Richard
  INET: [EMAIL PROTECTED]
Fat City Network Services-- 858-538-5051 http://

Re: minus vs. where not exists, vs. where not in

2003-09-21 Thread Mark Richard

I don't have any scientific proof but I imagine the sort_area_size could be
different between "not exists" and "minus".  When doing "minus" the entire
select string would have to be compared for equality, which could be very
large depending on your string.

Minus is probably an easier way (at least from a coding perspective) of
comparing every column in a table, or incorporating complexity in the
select statement.

Having said that.  Each statement has it's pros and cons and I guess it
depends on the volume of the various queries, etc.  For example, if the
have table A with 5 rows and table B with 100 rows executing "select
a.field from a where not exists (select 1 from b where b.field = a.field)
will result in 5 quick searches (assuming b.field is indexed) whereas
"select a.field from a where a.field not in (select b.field from b)" will
result in a full index read of b, as would "select a.field from a minus
select b.field from b".  Obviously different queries and different volumes
will tip the scales in different directions.

Regards,
  Mark.



   
   
  "Ryan"   
   
  <[EMAIL PROTECTED]To:   Multiple recipients of list 
ORACLE-L <[EMAIL PROTECTED]>  
  >cc: 
   
  Sent by: Subject:  minus vs. where not exists, 
vs. where not in 
  [EMAIL PROTECTED]
   
  .com 
   
   
   
   
   
  22/09/2003 03:59 
   
  Please respond to
   
  ORACLE-L 
   
   
   
   
   




Do any of you have any cases when minus is superior in performance? Ive
found 'not in' with a hash_aj to be the best option if the sub-query is
significantly less 'costly' then the outer query. I dont mean cost in terms
of the Explain Plan, I mean the work Oracle has to do to find a result set.
It also depends on a proper hash_area_size

I find 'where not exists' to be best if the subquery is relatively close in
cost to the outer query. Yes I know you cant make broad generalizations,
but there has to be some 'narrow' generalizations you can make. Such as
certain cases, etc...

what have you seen? There seems to be very little work in this area in the
literature.

Does 'where not exist' need more or less sort_area_size space than minus?


<<>>
   Privileged/Confidential information may be contained in this message.
  If you are not the addressee indicated in this message
   (or responsible for delivery of the message to such person),
you may not copy or deliver this message to anyone.
In such case, you should destroy this message and kindly notify the sender
   by reply e-mail or by telephone on (61 3) 9612-6999.
   Please advise immediately if you or your employer does not consent to
Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message
  that do not relate to the official business of
 Transurban City Link Ltd
 shall be understood as neither given nor endorsed by it.
<<<>




<<>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible for delivery of 
the message to such person), you may not copy or deliver t

Re: minus vs. where not exists, vs. where not in

2003-09-21 Thread Mladen Gogala
On 2003.09.21 15:24, Wolfgang Breitling wrote:
First off, the three are not equivalent, not substitutes for each other.  
Well not in and minus would be, but they are different from not exists. "not  
in"/"minus" and "not exists" can return different results. See
http://asktom.oracle.com/pls/ask/f?p=4950:8:F4950_P8_DISPLAYID:442029737684

for examples and explanation.

I have not done any performance comparisons but I personally routinely use  
minus and I am quite happy with it, especially across a db link.


Of course you do, because oracle brings the results of the whole remote
query over db link into the temporary tablespace of the local database.
Query like
select ename,job,dname
from emp e, [EMAIL PROTECTED] d
where e.deptno=d.deptno
will bring the whole dept table over the database link into the temporary
tablespace and perform join. The "not exist" condition may be faster if  
indexes are involved and if nested loops will give better results then sort/ 
merge, but those cases have to be carefully optimized and measured.
Now, a slight digression: exactly because of the database having tendency to
bring a ton of information over the database link, I frequently try to access
remote views to bring over just a few necessary records.

--
Mladen Gogala
Oracle DBA
--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author: Mladen Gogala
 INET: [EMAIL PROTECTED]
Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).


Re: minus vs. where not exists, vs. where not in

2003-09-21 Thread Ryan
if you handle for nulls with an 'nvl' then 'not exists' appears to return
the same answer as not in.

or am I wrong?
- Original Message -
To: "Multiple recipients of list ORACLE-L" <[EMAIL PROTECTED]>
Sent: Sunday, September 21, 2003 3:24 PM


> First off, the three are not equivalent, not substitutes for each other.
> Well not in and minus would be, but they are different from not exists.
> "not in"/"minus" and "not exists" can return different results. See
>
http://asktom.oracle.com/pls/ask/f?p=4950:8:F4950_P8_DISPLAYID:4420
29737684
>
>
> for examples and explanation.
>
> I have not done any performance comparisons but I personally routinely use
> minus and I am quite happy with it, especially across a db link.
>
> At 09:59 AM 9/21/2003 -0800, you wrote:
> >Do any of you have any cases when minus is superior in performance? Ive
> >found 'not in' with a hash_aj to be the best option if the sub-query is
> >significantly less 'costly' then the outer query. I dont mean cost in
> >terms of the Explain Plan, I mean the work Oracle has to do to find a
> >result set. It also depends on a proper hash_area_size
> >
> >I find 'where not exists' to be best if the subquery is relatively close
> >in cost to the outer query. Yes I know you cant make broad
> >generalizations, but there has to be some 'narrow' generalizations you
can
> >make. Such as certain cases, etc...
> >
> >what have you seen? There seems to be very little work in this area in
the
> >literature.
> >
> >Does 'where not exist' need more or less sort_area_size space than minus?
>
> Wolfgang Breitling
> Oracle7, 8, 8i, 9i OCP DBA
> Centrex Consulting Corporation
> http://www.centrexcc.com
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Wolfgang Breitling
>   INET: [EMAIL PROTECTED]
>
> Fat City Network Services-- 858-538-5051 http://www.fatcity.com
> San Diego, California-- Mailing list and web hosting services
> -
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (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).
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Ryan
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).


Re: minus vs. where not exists, vs. where not in

2003-09-21 Thread Wolfgang Breitling
First off, the three are not equivalent, not substitutes for each other. 
Well not in and minus would be, but they are different from not exists. 
"not in"/"minus" and "not exists" can return different results. See
http://asktom.oracle.com/pls/ask/f?p=4950:8:F4950_P8_DISPLAYID:442029737684 

for examples and explanation.

I have not done any performance comparisons but I personally routinely use 
minus and I am quite happy with it, especially across a db link.

At 09:59 AM 9/21/2003 -0800, you wrote:
Do any of you have any cases when minus is superior in performance? Ive 
found 'not in' with a hash_aj to be the best option if the sub-query is 
significantly less 'costly' then the outer query. I dont mean cost in 
terms of the Explain Plan, I mean the work Oracle has to do to find a 
result set. It also depends on a proper hash_area_size

I find 'where not exists' to be best if the subquery is relatively close 
in cost to the outer query. Yes I know you cant make broad 
generalizations, but there has to be some 'narrow' generalizations you can 
make. Such as certain cases, etc...

what have you seen? There seems to be very little work in this area in the 
literature.

Does 'where not exist' need more or less sort_area_size space than minus?
Wolfgang Breitling
Oracle7, 8, 8i, 9i OCP DBA
Centrex Consulting Corporation
http://www.centrexcc.com
--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author: Wolfgang Breitling
 INET: [EMAIL PROTECTED]
Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).