Subject Re: [firebird-support] Index/query opt?
Author Kjell Rilbe
Svein Erling Tysvær skriver:
> > select F2.ECO_ID
> > from F2
> > where exists (
> > select F1.ECO_ID
> > from F1
> > where F1.ECO_ID = 3504
> > and F2.TELNR = F1.TELNR
> > )
>
> Sorry Kjell, but there's no way to use an index for F2 with your query
> (there's no fixed value to look up). What I'd recommend if you use a Fb
> version that support CTEs, is to change the query to
>
> WITH MYTELNR AS
> (SELECT DISTINCT TELNR
> From F WHERE ECOID = 3504)
> SELECT F1.ECO_ID
> FROM F F1
> JOIN MYTELNR MTN on F1.TELNR = MTN.TELNR
>
> The result should be identical to your original query, but both indexes
> on ECO_ID and TELNR can be utilized.

Yes, I can see that. Thanks! Can't easily get the OO framework to change
the generated SQL, though. Later on I will make the system keep a
separate TELNR log for this purpose, resulting in a table with just a
few hundred recs to lookup and there will be an index too. :-) So,
there's no quick fix, then. Oh well...

Regards,
Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64