Skip to content
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

Auto Increment function #16445

Closed
WhiteTrashLord opened this issue Jun 10, 2017 · 5 comments
Closed

Auto Increment function #16445

WhiteTrashLord opened this issue Jun 10, 2017 · 5 comments
Assignees
Labels
O-community Originated from the community
Milestone

Comments

@WhiteTrashLord
Copy link

I have thought about your current SERIAL data type and came to the conclusion that I don't like it for all use cases. For example if I make a table for User data I would prefer to have very small INT user IDs.
So I would highly appreciate if you could add something like an auto increment function. Even if it's much slower. I think it's always good to give developers some more options.

@mahaben
Copy link

mahaben commented Jun 12, 2017

I agree with @WhiteTrashLord. It would be nice if you could provide something like an auto increment function instead of being obliged to use the serial data type!

@petermattis
Copy link
Collaborator

@WhiteTrashLord, @mahaben Is there a performance threshold at which this stops making sense? An auto-increment function requires central coordination of the counter. This might double the time to perform an insert.

I think it's always good to give developers some more options.

Many language and system designers would disagree with this. Your system can end up a confusing mess if this is taken to the extreme. This isn't meant to argue against your suggestion. I imagine the lack of small integer keys for an auto-increment type is surprising to many.

PS This is likely a dup of #5811

@bdarnell
Copy link
Contributor

Note that while it's not a function, you can get this behavior today with a subquery: INSERT INTO tbl (id, ...) VALUES ((SELECT ifnull(max(id), 0)+1 FROM tbl), ...);. This guarantees a gapless monotonic sequence if you're willing to pay the performance price. (if you can tolerate gaps you can improve performance by allocating the counter in a separate transaction)

@dianasaur323 dianasaur323 added the O-community Originated from the community label Jun 13, 2017
@cuongdo cuongdo added this to the 1.2 milestone Sep 6, 2017
@rjnn
Copy link
Contributor

rjnn commented Mar 1, 2018

@vilterp i assume you're no longer working on this task? I'm bumping the milestone to 2.1. Feel free to unassign yourself and reassign it to PMs for triage.

@rjnn rjnn modified the milestones: 2.0, 2.1 Mar 1, 2018
@bdarnell
Copy link
Contributor

bdarnell commented Mar 1, 2018

I think now that we have sequences this can just be closed.

@bdarnell bdarnell closed this as completed Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

No branches or pull requests

8 participants