Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: [oracle-l] Re: query plan is bad when it is run inside a pl/sql stored procedure
Technically the two queries are not the same unless particular condition (which is probably true, if the column names means what they suggest).
If there are duplicate rows in emktg_members (which is probably not the case, given the universal_id column) then the MINUS option reduces multiple occurrences to a single occurrence before the count takes place.
It is also possible that there are many gcd_data_source_details rows for each emktg_members rows (again the implication of the name of the universal_id is that there are not), in which case, the join in the second clause will be more expensive than the initial not exists.
By the way, you asked about '%TATA.COM', did the OP say anything about the '13' that appears in the correlated subquery - is this a literal too, or a bind variable in the pl/sql ?
The thing that puzzles me is that either version does an hash anti join unhinted. I have a test case that OUGHT to do a hash anti join for NOT EXISTS in 9.2.0.4, but doesn't even consider it. But (a) it does it with an UNNEST hint, and (b) the equivalent NOT IN subquery is automatically converted to a hash anti-join and, as it says in the manual, the first step of processing a NOT IN is to convert it into the equivalent NOT EXISTS and then optimise. (All columns are not null, unique constraints in place to help etc.... and the cost of the forced hash on NOT EXISTS is the same as the unforced hash on the NOT IN, and the cost of the FILTER that happens automatically as 12 times the cost of the hash).
Regards
Jonathan Lewis
http://www.jlcomp.demon.co.uk
The educated person is not the person
who can answer the questions, but the
person who can question the answers -- T. Schick Jr
Next public appearances:
Jan 29th 2004 UKOUG Unix SIG - v$ and x$
March 2004 Hotsos Symposium - The Burden of Proof
March 2004 Charlotte NC OUG - CBO Tutorial
April 2004 Iceland
One-day tutorials:
http://www.jlcomp.demon.co.uk/tutorial.html
Three-day seminar:
see http://www.jlcomp.demon.co.uk/seminar.html
____UK___February
____UK___June
The Co-operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/faq/ind_faq.html
Query
can be re-written like this:
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html -----------------------------------------------------------------Received on Wed Jan 28 2004 - 12:08:45 CST
![]() |
![]() |