Subject Re: [firebird-support] Re: Performance of the count Function.
Author Alexandre Benson Smith
Adam wrote:

>It is a bit more confusing, but still doable
>
>CountTable (X, Y, Amt);
>
>Then use your insert and delete triggers to fill the table
>
>X Y Amt
>==============
>1 1 1
>1 2 1
>2 3 1
>1 1 1
>1 2 1
>1 2 -1
>
>etc
>
>Your query on this table would look something like
>
>select sum(Amt)
>from counttable
>where Y in (1,2);
>
>your CountTable SP will have either a group by or nested queries to
>work out the sum for that X/Y combination, but in a nutshell,
>
>1) Sum the values of interest in the counttable.
>2) Delete the values of interest in the counttable.
>3) Insert a single value calculated in (1)
>
>The problem with count(*) is that it requires n complexity, so if you
>have 4 million records, it needs to add 4 million 1's together. With
>this methodology, providing the maintenance procedure is run
>reasonably often, you will probably only be adding together 400 1's.
>
>Adam
>
>
>
>
Yes, but I assume this could be done when one have a Defined number of
choices, if the search arguments have "unlimted" combinations (sometimes
one search criteria, sometimes 2, 3, etc). then this approach will not
work :-(

see you !

--

Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.2 - Release Date: 28/02/2005