| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: NextNumbers Tables
Jason W. Paul wrote:
>>If you want to do it that way, I'd go for the first approach. >>Just on caveat: The way to go is first increment the number then select
>>Otherwise, you'll run into trouble in a multiuser environment where two >>users want to insert at the same time.
Using transactions, you reach atomicity. If you have autocommit on, then of course there is no difference what you do first. On the other hand, then you don't have any atomic multi statements.
The reason for the difference is the way locking normally works unless
you have a very high isolation level (which leads to other lockouts):
- Select places a shared lock on a row
- Update places an exclusive lock on a row
Now picture two connection trying to get the next number simultanously:
Select first:
c1: Select current number -> shared lock c2: Select current number (still the same) -> shared lock c1: Update -> exclusive lock (might not even be possible!) c1: Commit -> release locks c2: Update -> exclusive lock c2: Commit -> release locks
Update first:
c1: Update number -> exclusive lock
c2: Update number -> wait for exclusive lock to be cleared, then
exclusive lock
c1: Select current number c1: Commit -> release locks c2: Now exclusive lock can be made; do update -> exclusive lock c2: Select current number c2: Commit -> release locks
Regards,
Heinz
Received on Fri Feb 14 2003 - 02:14:54 CST
![]() |
![]() |