Subject | Re: [firebird-support] If Not SELECT COUNT(*), Then What? |
---|---|
Author | Helen Borrie |
Post date | 2008-12-10T10:38Z |
At 09:14 PM 10/12/2008, you wrote:
./hb
>Hi Folks:It's an inefficient (and not very safe) way to perform an existence test.
>
> I had a bug in a function that is passed a table
>name and a where clause, and returns a count of the
>records that qualify for the where clause, if one is
>passed in.
>
> The function builds an SQL of
>
> SELECT
> COUNT(*) FROM
> <Table Name>
> WHERE <--------- If where clause passed in
> <Where Clause>;
>
> While tracking down the problem I read in Helen's
>book that SELECT COUNT(*) is inefficient.
> Should I re-think the use of COUNT(*) in this function?As long as you *need* it to COUNT things, no, there's no other way to count things. But if the idea is to count all the records so you can know ahead of time how many records there are going to be - as e.g. for a progress bar - then that's inefficient. But there are still a lot of people out there writing apps like that....and complaining about Firebird's performance... ;-)
./hb