Subject RE: [firebird-support] SELECT FIRST & COUNT
Author Ann W. Harrison
At 11:57 AM 4/12/2004, Alexandre Benson Smith wrote:

>What about write a "MinOf" UDF to do this ?
>
>Select
> MinOf(count(*), 2000)
>from
> MyTable

Much better would be a stored procedure. The UDF would count all the
records before discovering that it should have stopped at 2000.

create procedure limited_counter (limit_val long) returns (counter long)
as
begin
counter = 0;
for select 1 from <whatever> do
begin
counter = counter + 1;
if (counter > limit_val)
begin
counter = limit_val;
exit;
end;
end;
end;

There's no perceptible improvement in performance between select count (*)
and counting records in a procedure. In an engine that did not rely on
multi-generational entries in the index, count(*) would be more
efficient. But it's not for Firebird.

Regards,


Ann


Ann