-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: implement SERIAL column type #7032
Conversation
I think we'll need some good documentation explaining this choice.
|
Closes cockroachdb#4491. There are two good options for this, each with tradeoffs. One is for SERIAL to be an alias for DEFAULT unique_rowid and the other is to emulate Postgres's SEQUENCEs. Emulating SEQUENCE funnels every insert through a single point of contention, but would be a drop-in replacement. unique_rowid has no contention, is faster, and works for the common use of a unique and increasing identifier (modulo overlapping transactions). Unfortunately, it may also cause user confusion and break ORMs that (correctly in Postgres) assume that SERIAL starts at 0 and (incorrectly) that SERIAL has no holes. An interesting side benefit of unique_rowid is that it prevents the problem of inadvertantly exposing user growth numbers (sign up for a service once per day and keep track of the userids), which is a common issue with SERIAL. If it was known that user confusion and ORM compatibility would not be an issue, unique_rowid would be the clear decision. Since it's still early enough to run small experiments, this is the approach used here. If this results in sufficient evidence that it was the wrong decision, a later version of Cockroach will switch the behavior to emulate SEQUENCEs. Existing SERIAL columns will, however, retain the old behavior.
Agreed
|
Mind working with @jseldess on those docs? In particular, we should highlight how
|
Thanks for the mention. @paperstreet, I'll set up time to discuss. |
Happy to! In the meantime, I wrote up some quick notes cockroachdb/docs#356.
|
Excellent. Thanks, @paperstreet |
Docs covered by cockroachdb/docs#362 |
Closes #4491.
There are two good options for this, each with tradeoffs. One is for SERIAL to
be an alias for DEFAULT unique_rowid and the other is to emulate Postgres's
SEQUENCEs.
Emulating SEQUENCE funnels every insert through a single point of contention,
but would be a drop-in replacement.
unique_rowid has no contention, is faster, and works for the common use of a
unique and increasing identifier (modulo overlapping transactions).
Unfortunately, it may also cause user confusion and break ORMs that (correctly
in Postgres) assume that SERIAL starts at 0 and (incorrectly) that SERIAL has no
holes. An interesting side benefit of unique_rowid is that it prevents the
problem of inadvertantly exposing user growth numbers (sign up for a service
once per day and keep track of the userids), which is a common issue with
SERIAL.
If it was known that user confusion and ORM compatibility would not be an issue,
unique_rowid would be the clear decision. Since it's still early enough to run
small experiments, this is the approach used here. If this results in sufficient
evidence that it was the wrong decision, a later version of Cockroach will
switch the behavior to emulate SEQUENCEs. Existing SERIAL columns will, however,
retain the old behavior.
This change is