Subject Re: [ib-support] UDF query in select
Author Claudio Valderrama C.
""C Fraser"" <Colin.Fraser@...> wrote in message
news:000901c13caf$b0aa78f0$8f01a8c0@COLINFRASER...
>
> Select * from Contact
> where
> UC_Name Like 'SMITH%'
> OR
> Soundex_Name = F_GenerateSndxIndex('Smith')
>
> This query is a bit slower than what I had thought, for example, the
> time taken to a Select * from Contact where UC_Name = 'SMITH%' plus the
> time taken to do the other soundex query separately is quite a bit
> shorter than doing the one query with the or. (both fields are indexed)
>
> In the query above, is the GenerateSndxIndex UDF called once for every
> row, or is it only done once...

Colin,
short boolean circuit or "leave as soon as you have enough to evaluate a
condition" is a property of typical programming languages. As I see things,
the SQL standard says you should evaluate a full expression. Anyway, FB's
internal code does complete evaluation of expressions. This means that your
OR shown above has to evaluate both operands even if the first one is true.

Also, in your example, your UDF is evaluated for every record. UDF
invocation has a penalty in performance when compared with native built-in
functions.

C.