Subject Re: SELECT COUNT performance
Author Svein Erling
--- In firebird-support@yahoogroups.com, "sqlsvr" <sqlsvr@...> wrote:
>
> The query: SELECT COUNT(*) FROM accounts will run incredibly slow on a table that has half a million records. I thought it would use a key by default? SQL Server could return it in half a millisecond.
>
> Shouldn't a COUNT query be fast?

No, the way Firebird handles concurrency, means that it has to look at every record in the table for the result to be correct, and hence it is slow. Take a look at www.firebirdfaq.org/faq5/ for an explanation of how to make quick counts when required (I think many count(*) without a WHERE clause are issued for situations when it is convenient, but not really required. For larger tables, you then learn that you might want to do things other ways).

Set