Subject | Re: SELECT COUNT performance |
---|---|
Author | sqlsvr |
Post date | 2010-07-10T12:14:53Z |
Thanks for the response. The resource states:
Reason is that Firebird doesn't keep information about number of records in database. Since query doesn't have WHERE clause, it cannot use index either, and has to go through all the records.
But my query DOES have a where clause (it is an indexed column) and it is very slow.
Reason is that Firebird doesn't keep information about number of records in database. Since query doesn't have WHERE clause, it cannot use index either, and has to go through all the records.
But my query DOES have a where clause (it is an indexed column) and it is very slow.
--- In firebird-support@yahoogroups.com, "Svein Erling" <svein.erling.tysvaer@...> wrote:
>
> --- 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
>