MySQL Assuming autoincremented IDs based on multi value insert and first id

97 Views Asked by At

Just wanted to runt this by someone who knows more MySQL than myself

I perform a MySQL insert where I insert say 10 rows in one query. Then when you get MySQL's last insert id, it gives you the ID of the first inserted ID.

Is it safe to assume that the other IDs are consecutively the insert_id - insert_id+9? or is there any possible way this could not turn out to be the case?

Thanks

1

There are 1 best solutions below

1
On

Yes, there is a possibility this will not always be the case.

With innodb_autoinc_lock_mode = 2, the rows inserted by a single INSERT statement can be assigned AUTO_INCREMENT values that are not consecutive (when concurrent INSERT statements are running.)

http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html