Subject Re: [ib-support] Speed of Joins
Author lele@seldati.it
>>>>> On Thu, 02 May 2002 12:16:14 -0000, "sean_brad" <sean_brad@...> said:

sb> Hi I use a join select statement of the following form:

sb> SELECT A,B,C FROM Table1 LEFT OUTER JOIN Table2 ON Table2.D =
sb> Table1.D and Table2.E = Table1.E Where F like 'text%'

sb> ...

sb> I've tried replacing it with:

sb> SELECT A,B,C FROM Table1, Table2 Where Table2.D = Table1.D and
sb> Table2.E = Table1.E and F like 'text%'

sb> and the result set is returned much quicker.

sb> Can any one explain why the first method is so much
sb> slower.

Those queries are not equivalent! The latter is more an "INNER JOIN"
than a "LEFT OUTER". The former does return A,B,C (assuming they come
from Table1) where there is no record on Table2 that satisfy the
condition T2.D=T1.D. In this case FB may select a PLAN that cycles
over T1, even if the condition on field F (I'm guessing again it's a
Table2 field) should have used an index on T2...

sb> And, if there is a good reason for using it, is there
sb> a way of speeding it up?

Well, I think it does depend on what exactly you would like to obtain
:)

And, BTW, take the good habit of fully specify a field, I mean saying
"TableX.F like ...." instead of just "F like..": it make it easier to
understand both for humans and for FB :)

hth,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri
real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia.
email: lele@... | -- Fortunato Depero, 1929.