1
realkenshinji 2018 年 10 月 16 日 via iPhone
被删了?
|
2
eslizn 2018 年 10 月 16 日 是不是业务里有事务插入后没提交回滚了
|
3
fy1993 2018 年 10 月 16 日
赞同 2 楼 事务回滚,主键会跳增
|
4
glacer 2018 年 10 月 16 日
replace, insert into ... on duplicate key 这类语句都会删行
|
5
xiaoxinshiwo 2018 年 10 月 16 日
看了下 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 2018 年 10 月 16 日
“ 丢失 ”自动递增值和序列间隙
在所有锁定模式( 0,1 和 2 )中,如果生成自动增量值的事务回滚,则这些自动增量值将“ 丢失 ”。一旦为自动增量列生成了值,就无法回滚它,无论 “ INSERT-like ” 语句是否完成,以及是否回滚包含的事务。这些丢失的值不会被重复使用。因此,存储在 AUTO_INCREMENT 表的列中的值可能存在间隙 。 |
7
est 2018 年 10 月 16 日
AUTO_INCREMENT 有预分配的。没用完很正常。
|
8
dengtongcai 2018 年 10 月 16 日
@glacer replace into 会删行,inster into 不会的吧
|
9
qiyuey 2018 年 10 月 16 日
这个是先申请,后使用,申请了没使用就跳了。
像事务、insert or update 都会导致。 |
10
gaius 2018 年 10 月 16 日
我这有个表用的 select on duplicate key,前段时间都把 int 用完了,应用插不进去了. 控制台还能插最后一个是最骚的
|
11
opengps 2018 年 10 月 16 日 via Android
添加失败呗,比如某些约束不满足,返回错误,但是 id 还是占用的
|
12
bobuick 2018 年 10 月 16 日
间隙锁会导致主键出现这种情况。
|
13
gaius 2018 年 10 月 16 日
insert..
|
14
Leigg 2018 年 10 月 16 日 via iPhone
肯定有骚操作
|
15
kiddult 2018 年 10 月 16 日
@dengtongcai insert 会,不管成功失败都会自增
|
16
littlewing 2018 年 10 月 16 日
这是 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 2018 年 10 月 17 日
on duplicate 就会这样
其实是先删了一条再插的 |
23
q397064399 2018 年 10 月 18 日
要连续干嘛,主键
|
24
tinyhill 2018 年 10 月 18 日
一般是事务回滚导致,也有可能是插入被物理删除导致。但自增 ID 连续没啥用,不要有洁癖...
|
25
qianbi6 2018 年 12 月 16 日 via Android
引擎用了 innodb 了吧 innodb 会出现这问题
|
26
c4f36e5766583218 2019 年 2 月 22 日
既然知道原因了,如果强迫症的话,了解一下: https://www.v2ex.com/t/529758
|