Subject Re: [firebird-support] Re: Firebird Trigger Local Variable Gotcha
Author Ann W. Harrison
t.s. wrote:
> So maybe to prevent the same bug to ever see me face to face again,
> would it be better to change the "check whether something exists"
> construct from :
> ...
> select (blah) from (blah_table) into :blah_var;
> if (:blah_var is null) then begin
> -- normal processing here
> end;
> ...
>
> to
> ...
> if (exists(blah blah blah)) then begin
> select (blah) from (blah_table) into :blah_var;
> ...
> -- normal processing here
> end
> ...
>
> The downside is that it'd be slightly slower due to having to do the
> query twice.

A LOT slower. How about

:blah_var = NULL;
> select (blah) from (blah_table) into :blah_var;
> if (:blah_var is null) then begin
> -- normal processing here

Assigning a value to a variable is approximately free. Running an
exists test involved (for the first time) parsing, compiling,
and optimizing a separate query and (every time) executing the
query with (one hopes) indexed reads, data reads, evaluation, etc.

Regards,


Ann