spacemilkman
spacemilkman

Reputation: 973

MySQL insert with autoincrement - is insert ignore neccessary to avoid concurrency issue?

I am using the simple INSERT statement in MySQL with innodb, with auto-increment in the primary id. Do I need to worry about if user A and user B execute the same script at the same moment, user A's insertion would be overwritten by user B's?

Upvotes: 1

Views: 198

Answers (1)

Michal Borek
Michal Borek

Reputation: 4624

No, it will not. You can treat it as thread safe.

From reference:

When accessing the auto-increment counter, InnoDB uses a special table-level AUTO-INC lock that it keeps to the end of the current SQL statement, not to the end of the transaction

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

Upvotes: 1

Related Questions