How is the MySQL auto_increment step size determined

Several suggestions of why this may be happening:

See auto_increment_increment. This controls the incrementation each time a new value is requested during INSERT.

Also if you use InnoDB tables in MySQL 5.1, they optimized auto-inc allocation so that it locks the table for a shorter duration. This is good for concurrency, but it can also "lose" auto-inc values if the INSERT of a row conflicts with another constraint such as a secondary UNIQUE column or a foreign key. In those cases, the auto-inc value allocated is not pushed back into the queue, because we assume another concurrent thread may have already allocated the next auto-inc value.

Of course rollbacks also occur, in which case an auto-inc value may be allocated but discarded.


It could be related to transactions that end up getting rolled back. For example,

  1. Insert google.com id=5
  2. Insert mysql.com id=6
  3. Insert stackoverflow.com id = 7
  4. rollback insert google.com
  5. rollback insert mysql.com

Then stackoverflow.com is inserted with id=7 and 5 and 6 are left blank.