1
realkenshinji Oct 16, 2018 via iPhone
被删了?
|
2
eslizn Oct 16, 2018 是不是业务里有事务插入后没提交回滚了
|
3
fy1993 Oct 16, 2018
赞同 2 楼 事务回滚,主键会跳增
|
4
glacer Oct 16, 2018
replace, insert into ... on duplicate key 这类语句都会删行
|
5
xiaoxinshiwo Oct 16, 2018
看了下 mysql 官方文档,还挺复杂
The exception is for “ mixed-mode inserts ”, where the user provides explicit values for an AUTO_INCREMENT column for some, but not all, rows in a multiple-row “ simple insert ”. For such inserts, InnoDB allocates more auto-increment values than the number of rows to be inserted. However, all values automatically assigned are consecutively generated (and thus higher than) the auto-increment value generated by the most recently executed previous statement. “ Excess ” numbers are lost. 参考: https://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html |
6
xiaoxinshiwo Oct 16, 2018
“ 丢失 ”自动递增值和序列间隙
在所有锁定模式( 0,1 和 2 )中,如果生成自动增量值的事务回滚,则这些自动增量值将“ 丢失 ”。一旦为自动增量列生成了值,就无法回滚它,无论 “ INSERT-like ” 语句是否完成,以及是否回滚包含的事务。这些丢失的值不会被重复使用。因此,存储在 AUTO_INCREMENT 表的列中的值可能存在间隙 。 |
7
est Oct 16, 2018
AUTO_INCREMENT 有预分配的。没用完很正常。
|
8
dengtongcai Oct 16, 2018
@glacer replace into 会删行,inster into 不会的吧
|
9
qiyuey Oct 16, 2018
这个是先申请,后使用,申请了没使用就跳了。
像事务、insert or update 都会导致。 |
10
gaius Oct 16, 2018
我这有个表用的 select on duplicate key,前段时间都把 int 用完了,应用插不进去了. 控制台还能插最后一个是最骚的
|
11
opengps Oct 16, 2018 via Android
添加失败呗,比如某些约束不满足,返回错误,但是 id 还是占用的
|
12
bobuick Oct 16, 2018
间隙锁会导致主键出现这种情况。
|
13
gaius Oct 16, 2018
insert..
|
14
Leigg Oct 16, 2018 via iPhone
肯定有骚操作
|
15
kiddult Oct 16, 2018
@dengtongcai insert 会,不管成功失败都会自增
|
16
littlewing Oct 16, 2018
这是 feature,不是 bug。mysql 只保证了自增 ID 递增,并没有保证连续
https://dev.mysql.com/doc/refman/5.7/en/innodb-auto-increment-handling.html#innodb-auto-increment-initialization https://blog.csdn.net/ashic/article/details/53810319 https://www.cnblogs.com/zengkefu/p/5683258.html 可以看看这几篇文章 |
21
Raymon111111 Oct 17, 2018
on duplicate 就会这样
其实是先删了一条再插的 |
23
q397064399 Oct 18, 2018
要连续干嘛,主键
|
24
tinyhill Oct 18, 2018
一般是事务回滚导致,也有可能是插入被物理删除导致。但自增 ID 连续没啥用,不要有洁癖...
|
25
qianbi6 Dec 16, 2018 via Android
引擎用了 innodb 了吧 innodb 会出现这问题
|
26
c4f36e5766583218 Feb 22, 2019
既然知道原因了,如果强迫症的话,了解一下: https://www.v2ex.com/t/529758
|