Subject [firebird-support] Re: Parameterised like query won't use index in the plan
Author Svein Erling Tysvær
>> I tried manually LIKE with and without the addition of STARTING WITH
>> and tried what I thought was likely to have worse performance with
>> STARTING WITH - when the parameter starts with a wildcard. With
>> STARTING WITH, my query executed in 5.4 seconds, without it 4.6
>> seconds. So, in my simple test, the additional overhead was about 17%.
>> The other extreme, with the wildcard at the end, STARTING WITH
>> executed in 0.3 seconds, vs 4.5 seconds without STARTING WITH, i.e.
>> STARTING WITH is 15 times quicker. So, what determines whether such an
>> addition will be harmful or benefitial, is (no surprise) what the
>> parameter looks like.
>
>Interesting to see! Thanks! Just one question: in the first case, wildcard at beginning,
>did you write starting with '%xyz' or did you extract the prefix up to the first wildcard,
>i.e. an empty string: starting with ''? It was the latter I intended.

I did as you intended, Kjell. My query was similar to

SELECT *
FROM PERSON
WHERE NAME LIKE :Param1
OR NAME STARTING WITH :Param2

Then I set Param1 to '%VOFF%' and left an empty string in Param2. The query didn't return any rows.

Set