I have a question about concurrency control and when to worry about that. I’ve created a PHP/MySQL site (InnoDB). I know about how to avoid transaction issues but then there is the concurrency control.
My site is an E-commerce which holds user inserted goods, so as an example. When a user inserts a new item to the site, the DB creates an productId as primary key ( auto-incremented by the DB ) and stores the other data about that product that is submitted through a form. I’m using prepared statements.
Do i have to worry about if two or more users are doing this at exactly the same time? Is there any chance that submitting two or more items at the same time will mess up the data of the different rows?
To be able to insert products the user has to be logged in using sessions if that matters to the question.
Thanks in advance, Markus.
Unless they’re writing to the exact same row, I don’t see why you’d have any concurrency issues. Even if they were writing to the same row, InnoDB has row-level locking in place, which means that a row will be locked until a user has finished writing to it, leaving subsequent users to “wait it out” until the lock has been released. In regards to the possibility of “conflicting INSERT queries”: If you’re inserting new data into a table that is using an auto-incrementing primary key, you’re guaranteed to get a unique ID each time, which means that concurrency should never be an issue on INSERT.