Why are numbers being skipped in my auto-increment primary key?

岁酱吖の 提交于 2020-01-06 04:57:06

问题


Using MySQL 5.1.37

This isn't really a critical issue, one of our biz-dev people just asked about it and I didn't have a good answer. In our users table we have an auto-increment primary key. From time to time, it skips numbers and seems to be doing so at an increasing rate. My original thought was that when two concurrent signups occurred and one was invalid, that if the second signup was in progress while the first was failing, we would see skipped values since the second signup would use the next ID. But this doesn't seem that likely because of the frequency with which it happens. Any ideas?


回答1:


I think you are on the right lines with the failed setups. It could be the result of transactions “reserving” a primary key and then the transaction being rolled back. This is of course assuming that there is no kind of delete statements being issued on the table




回答2:


The following answer this question:

MySQL Auto Increment Columns on TRANSACTION, COMMIT, and ROLLBACK

MySQL AUTO_INCREMENT does not ROLLBACK

http://bugs.mysql.com/bug.php?id=30767



来源:https://stackoverflow.com/questions/3566936/why-are-numbers-being-skipped-in-my-auto-increment-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!