Re: Problem With Exists in 7.3
Posted in 1998
Topics: Performance & Tuning, SQL Development & Query Writing
Also sprach "Alexander V.Didytch" <unknown.thegreat@usa.net> :
:create temp table a (a_id integer) with no log;
:create temp table b (b_id integer) with no log;
:Insert into a select ........ (many rows)
:insert into a select ROWID from a; -- (it has a lot of rows)
:select * from b,a where a.ROWID=b.b_id; -- (returns a lot of rows)
:And now the PROBLEM:
:select * from a
:where exists (select * from b where a.ROWID=b.b_id);
I ran this on 7.30 on NT. I had to make some small changes, as you didn't say
what data was originally inserted. I did as follows:
create temp table a (a_id serial) with no log;
create temp table b (b_id serial) with no log;
--Repeat the next 2 many times to get a couple dozen rows in each table
Insert into a values(0);
insert into b values(0);
insert into b select ROWID from a; -- (it has a lot of rows)
^^Since you are trying to join the ROWID from table a with table b values, don't
you want to insert the rowids from a into b? I didn't know how to get valid
matches for the join any other way. Since you don't use a.a_id anywhere in your
queries, I don't see what difference the values in table a make anyway.
select * from b,a where a.ROWID=b.b_id;Works fine.
--And now the PROBLEM:
^^^^^^^^^^
set explain on;
select * from a
where exists (select * from b where a.ROWID=b.b_id);
Also works fine - no problems at all.
7.3 will do unnesting of correlated subqueries whenever possible, but that
should not change the results. I would examine the query plan produced by set
explain on both versions and see if they differ at all.
Dave (posting from home, speaking as a representative of nobody but himself)
**********
"Everybody plays the fool, sometimes."