InnoDB is a transactional engine.
This means that in the following scenario:
Session Ainserts record1Session Binserts record2Session Arolls back
, there is either a possibility of a gap or session B would lock until the session A committed or rolled back.
InnoDB designers (as most of the other transactional engine designers) chose to allow gaps.
From the documentation:
When accessing the auto-increment counter,
InnoDBuses a special table-levelAUTO-INClock that it keeps to the end of the currentSQLstatement, not to the end of the transaction. The special lock release strategy was introduced to improve concurrency for inserts into a table containing anAUTO_INCREMENTcolumn…
InnoDBuses the in-memory auto-increment counter as long as the server runs. When the server is stopped and restarted,InnoDBreinitializes the counter for each table for the firstINSERTto the table, as described earlier.
If you are afraid of the id column wrapping around, make it BIGINT (8-byte long).