I'm working on an application backed by a MySQL instance, and I've encountered strange behavior involving what seems to be "phantom" inserts.
Given a table with an auto-incrementing integer key, I perform the following:
INSERT ... // generates ID 1INSERT ... // generates ID 2INSERT ... // generates ID 3SELECT * // returns the set of elements 1 and 3
It seems like the second insert generates an ID and returns to the client before the insert is finished, so I can simultaneously know the ID and not be able to select the data yet. This is surprising - I would think that the insert would not return until the row is inserted.
Is there a way to tell MySQL both allocate an ID and insert a row in one atomic operation, so that, once I know of the ID 2, it is guaranteed to come back from a select query?