Jump to content

is it safe to assume that auto_increment is atomic during select?


ala888

Recommended Posts

Is it safe to assume that auto_increment is atomic during select operations?

example, If I insert 1000 rows instantly (hypothetically), okay, I know that auto_increment will increment one by one. but can I be sure that ALL select operations during, before, after this insert will always show auto_increment (10) before auto_increment (20) ?

 

Like for some arbitrary optimization reason, even though a row with auto_increment (1) exists, the select operation will get 1,2,3..9,11,20

before a millisecond later 1,2,3,9,10,11,20 ?

 

Or will this never occur?

Link to comment
Share on other sites

  • 2 weeks later...

The database doesn't count all of the rows that are going to be inserted and then starts inserting them in a random order, it will just sequentially insert rows as it gets to them. So yes, it will use lower numbers first.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...