Subject Re: [firebird-support] Very slow SQL
Author Alexandre Benson Smith
Ed Dressel wrote:
> I have the following SQL statement:
>
> select * from ClientINfo
> where Client_Id in (Select Max(Client_ID) from ClientInfo)
>
> where Client_ID is the primary key of ClientInfo.
>
> But the SQL above is very slow (almost 2 minutes). The plan is nautrual:
>
> PLAN (CLIENTINFO NATURAL)
> PLAN (CLIENTINFO NATURAL)
>

Max(Client_ID) will return just one value, so change IN to =

select * from ClientINfo
where Client_Id = (Select Max(Client_ID) from ClientInfo)

add a descending index on ClientInfo(Cliente_ID)


see you !



--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br