This repository was archived by the owner on Jan 4, 2020. It is now read-only.
Conversation
zhiqiangbuxi
commented
Sep 30, 2016

- 描述:批量循环写入时,出现主键不连续的情况,跳跃增长(请自行测试)
- 紧急程度:严重
- 原因:innodb中insert操作分为三种情况:Simple inserts,Bulk inserts,Mixed-mode inserts,其中Simple inserts这种MySQL引擎提前知道要插入的行数,而后两种并不知道,针对三种情况mysql提供, innodb_autoinc_lock_mode 配置参数,设置为0,1(默认)或2,分别为 “ 传统的 ”,“ 连续的 ”, “ 交错 ”锁定模式。在官方默认的insert into table() (select *) union all (select *).... 属于Bulk inserts所以会造成主键不连续,反之insert into table() values(),().....属于Simple inserts则不会。除非手动修改innodb_autoinc_lock_mode=0,也就是采用传统锁模式,所有insert操作都要申请auto-inc锁。
- 文献:http://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html
- PS:希望官方测试后,完善该BUG
Member
|
这么设计就是为了通用化考虑 你这种有些数据库没法支持 |
Author
|
原来这样,看来只有在自己的项目修改了,但是addAll()这个导致主键不连续这也是个大坑。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.