Subject | RE: [firebird-support] SELECT FIRST & COUNT |
---|---|
Author | Ann W. Harrison |
Post date | 2004-04-12T16:20:21Z |
At 11:57 AM 4/12/2004, Alexandre Benson Smith wrote:
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
>What about write a "MinOf" UDF to do this ?Much better would be a stored procedure. The UDF would count all the
>
>Select
> MinOf(count(*), 2000)
>from
> MyTable
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