Subject RE: [firebird-support] IS this the right thing to do (trigger)
Author Leyne, Sean
Robert,

> Overview
> I have a large table (5 - 20 million records) that I regularly need to
> do grouped counts on. this is slow. My planned solution is to have a
> counting table updated by triggers. I would like to know what people
> think of the following proposed solution. Will it work properly, what
> sort of performance hit will be involved, is there a better way?

What is the frequency of running the counts query?


> And the following triggers to maintain totals....

> CREATE TRIGGER BranchSend_Edit FOR BranchSend
> AFTER EDIT POSITION 10
> AS BEGIN
> IF (OLD.TransferConfirmed = 'F')
> AND (New.TransferConfirmed = 'T') THEN
>
> UPDATE BranchSendCount
> SET AvailableRecs = AvailableRecs - 1
> WHERE RegionRef = NEW.RegionRef
> AND SendTable = NEW.SendTable;

I think you really meant:

SET AvailableRecs = AvailableRecs **+** 1


Sean