Subject Re: select count(*) is slow
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, Jonathan wrote:
> I hope that future version of firebird will come with better
> performance for this Count() function. Will it on version 2.0 ?

The problem is the multigenerational architecture. There may exist
several versions of the same record and only one of those versions
will be visible to the transaction doing the count. There is no way of
knowing whether or not to include a particular record in the count
without taking a look at it. And taking a look at - say 10 million
records does take a bit of time.

The suggestion in the link you were shown could solve the problem for
"select count(*) from <table>", but would fail as soon as changing to
"select count(distinct <field> from <table>" or "select count(*) from
<table> where ...".

Hence, the only "easy" way to make counting lightning fast, is to
remove the multi-generational architecture and removing the heart is
not a good way to stop the bleeding. Counting is one area where
Firebird can never compete with desktop databases, you simply have to
be careful about when you use it (and often, there are other
alternatives).

Set