Board index » delphi » IBQuery not using table index with LIKE and parameters?

IBQuery not using table index with LIKE and parameters?

John,

If your wildcard characters are always going to be at the end of your
search string (as in your "SMITH%" example), then use a "STARTING
WITH" clause instead of a "LIKE" clause.  Interbase will use the index
then, even with parameters.

Brian

On Mon, 24 Jan 2000 07:50:38 +1100, "John Manning"

Quote
<johngmann...@yahoo.com> wrote:
>I have a table (customer) which has an index on the column "surname". If I
>have an IBQuery with the following SQL:

>SELECT * FROM customer WHERE surname LIKE :surname

>and I specify the value 'SMITH%' for the parameter 'surname' then the query
>produces the correct results but does not use the index (verified through
>SQL Monitor).

>If I "hard code" the query as "SELECT * FROM customer WHERE surname LIKE
>'SMITH%'" then it uses the index as expected.

>Is there a particular trick I need to use here in order to get the query to
>use the index?

>Thanks,
>John

 

Re:IBQuery not using table index with LIKE and parameters?


I have a table (customer) which has an index on the column "surname". If I
have an IBQuery with the following SQL:

SELECT * FROM customer WHERE surname LIKE :surname

and I specify the value 'SMITH%' for the parameter 'surname' then the query
produces the correct results but does not use the index (verified through
SQL Monitor).

If I "hard code" the query as "SELECT * FROM customer WHERE surname LIKE
'SMITH%'" then it uses the index as expected.

Is there a particular trick I need to use here in order to get the query to
use the index?

Thanks,
John

Other Threads