Subject Can I get FB to use index in this query?
Author Kjell Rilbe
Hi,

This concerns SQL generated by an O/R mapper, so please don't tell me
how to improve the SQL (I'm trying to bring it to the dev team's attention).

Anyway, the SQL is as follows:

SELECT Company.Id
FROM Company
WHERE EXISTS (
SELECT Id
FROM Country
WHERE Company.Country = Country.Id
AND Country.Code = ?
)

I think the semantics are pretty obvious. Of course better SQL with
equivalent sematics would be:

SELECT Company.Id
FROM Company
JOIN Country on Country.Id = Company.Country
WHERE Country.Code = ?

The latter SQL will let FB use an index on Company.Country, but the
former SQL will always cause FB to scan the entire Company table. If
this table is large and the index has good selectivity, this is a huge
performance hit.

So, is there any way I can get FB to use the index for the first query?

Kjell

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