Subject Re: [ib-support] How Do I count faster?
Author Ann Harrison
At 07:31 PM 5/26/2003 -0300, Roque wrote:

>:. What about creating a trigger on insert/delete operations to
>increment/decrement a number in another table? Is that too much expensive to
>the general performance?


The problem is that you'll often get deadlocks (lock conflicts) in
a multi-user system. An alternative that does not deadlock is to
count the records once, put that value in a table (e.g.
insert into invoice_count (invoice_count) values (34521);
then store 1 each time a record is added and -1 each time one
is deleted. The count is SUM (invoice_count) FROM INVOICE_COUNT.
To make it fast, you'll need to do a periodic sum, update the
first record, and delete the others.


Regards,


Ann