Subject Re: Maintaining proper generator values
Author Svein Erling
--- In firebird-support@yahoogroups.com, Doug Chamberlin
<yahoogroups@a...> wrote:
> At 11/11/2003 02:52 PM (Tuesday), Milan Babuskov wrote:
> >One more thing, why max+1 ?
> >Setting it to max is enough.
>
> Actually I just double checked and found that the value in use is
> really max+20.
>
> The reason for this is due to the fact that generator operations are
> outside of transaction control. Therefore, in the sequence of 1)
> determining of max value existing in tables, 2) determining current
> generator value, 3) comparing the two, 4) resetting the generator,
> there could be concurrent operations which are altering those
> values. Therefore, we reset to max plus a comfortable margin which
> hopefully puts the new value past any current activity effects.

Doug, I see that your approach is pretty safe, but

SET <GeneratorName> TO <Max+20>

still has a small, theoretical chance of creating problems, whereas

GEN_ID(<GeneratorName>, <Max-PreviousGeneratorValue>)

should always be safe provided PreviousGeneratorValue is less than or
equal to Max (well, up to the maximum value a generator can hold).

Set