Subject | Re: [firebird-support] Inappropriate optimization? |
---|---|
Author | Helen Borrie |
Post date | 2005-09-25T06:02:26Z |
At 04:25 AM 25/09/2005 +0000, you wrote:
t.field, if there is one, which might make it faster, if it was a useful
index. A parameter is not a variable, it is a placeholder for a value, so
a test like "where Null = Null" is not just logically absurd, it will
prevent an index being used.
If you are going to use a null parameter as a mechanism for not applying a
search, you should code your procedure accordingly.
if (:param is null) then
begin
for select ....
<no where clause>
...
end
else
begin
for select...
where t.field = :param
....
end
./hb
>In pseudo codeCorrect syntax in the search clause would make the engine use an index on
>
>create procedure (param integer)
>begin
> for select * from table t
> where (:param is null) or (t.field = :param)
> suspend;
>end
>
>The intention was to enable procedure to return all
>records if a parameter is not provided. Aditional
>conditions are posible. When parameter is provided
>we have unindexed reads of all records in a table,
>causing extreme slow execution.
>
>Is there a way to make this possible and fast?
t.field, if there is one, which might make it faster, if it was a useful
index. A parameter is not a variable, it is a placeholder for a value, so
a test like "where Null = Null" is not just logically absurd, it will
prevent an index being used.
If you are going to use a null parameter as a mechanism for not applying a
search, you should code your procedure accordingly.
if (:param is null) then
begin
for select ....
<no where clause>
...
end
else
begin
for select...
where t.field = :param
....
end
./hb