Subject Re: [firebird-support] "Generators" via table data
Author Ann W. Harrison
tdtappe wrote:
>
> So let's assume I have a table that contains all counters and each
> counter is referenced by a unique name (primary key).
>
> What would be the best way (performance) to implement a counter
> increment. Of course, a client application must not get a counter value
> that another client has already got. Just the way generators work in
> firebird.

The reason generators work the way they do is to avoid serializing
inserts. When numbers are generated from a table, they're constrained
by transactional rules ... only one transaction can change the
generator value and nobody else can get a value until that transaction
ends. So, if you want to insert a number of records in a single
transaction, you'll block others for the duration of the transaction.

But, you have to do it your way.

So, one solution is to start a transaction, update the appropriate
counter, read the counter, commit your transaction, start a second
transaction, do whatever you need to do for the insert, commit and
begin again. The transaction that reads the counter should be a
snapshot, wait transaction and it should have error handling that
allows it to rollback and retry in the case of deadlocks.

Or, have your application create generators as necessary.


Regards,


Ann