Next: Summary
Up: Numbering Rows
Previous: Serial Column Type
Manually Numbering Rows
Some people wonder why OIDs and sequences are needed at all. Why can't
a database user just find the highest number in use, add one, and use the result
as the new unique row number? In reality, OIDs and sequences are preferred
for several reasons:
- Performance
- Concurrency
- Standardization
First, it is usually a slow process to scan all numbers currently in use to
find the next available number. Referring to a counter in a separate location
is faster. Second, if one user gets the highest number, and another user is
looking for the highest number at the same time, the two users might choose
the same next-available highest number. Of course, in this case, the number
would not be unique. Such concurrency problems do not occur when using OIDs
or sequences. Third, it is more reliable to use database-supplied unique number
generation than to generate unique numbers manually.
Bruce Momjian
2001-05-09