Subject Re: [firebird-support] Re: Generators for auto-increment - with override
Author Daniel L. Miller
Ann W. Harrison wrote:

>Daniel L. Miller wrote:
>
>
>
>>Assuming I trust any manually specified id - sometimes I'm paranoid
>>enough that I don't even trust myself. The max() check was the simplest
>>way I came up with to guarantee the validity of the id.
>>
>>
>
>People familiar with Firebird are very hesitant to use a MAX check
>because it requires a full table scan unless the field has a descending
>index. Primary key indexes are ascending. (Interesting question... what
> would break if we changed that?) Pierre Y. (?) suggested comparing
>the key provided to the current generator value and incrementing the
>generator by the difference if the key provided was larger. That works
>and doesn't involve reading all the records in the table whenever a key
>is provided.
>
>Regards,
>
>
>Ann
>
>
This assumes that either the generator value or the specified key is
still greater than any existing record in the table. That may be a
perfectly reasonable assumption - but it's not a guarantee.

--
Daniel