Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Why this query is SO slow?
I can think of a number of reasons. Here are the first batch.
SELECT id
FROM pbase p
WHERE NOT EXISTS (
SELECT id
FROM pbase2 b
WHERE p.id = b.id);
Amazingly enough this query often also runs far faster than the NOT IN as you wrote it:
SELECT DISTINCT id
FROM pbase
WHERE id NOT IN (
SELECT id
FROM pbase
MINUS
SELECT id
FROM pbase2);
But no matter what else you do ... make sure indexes exist on both tables (I am assuming they are large) and that you create statistics and then run EXPLAIN PLAN to verify that the indexes are being used.
If you still have problems let us know.
Daniel Morgan
Max Wilson wrote:
> As subject:
>
> SELECT id
> FROM pbase
> WHERE id NOT IN
> (SELECT id FROM pbase2);
>
> It takes oven an hour to run.
>
> Thank you
> Manuel
>
> P.S. Sorry if my english not good
Received on Sun Apr 14 2002 - 18:50:54 CDT