Sample Header Ad - 728x90

How to ensure that two or more simultaneous requests to a MySQL table don't interfere

1 vote
2 answers
1821 views
Suppose I have about a 1000 simultaneous requests to a table in my DB which consists of these statements (in order): SELECT INSERT or UPDATE (could be multiple) DELETE and I want to make sure that none of the requests interfere with one another and the table is in an updated state for the next incoming request. For example: Request #1 comes in. Request #2 comes in. Request #1 starts to get processed. Request #2 should start only when Request #1 is processed so that the data view is consistent and updated for the next request. I searched for this situation around the web and found out two things that could be of help: 1. Transactions 2. Table Locking But when I read about Transactions, I found out that while a row is being processed by a transaction, other transactions can still come along and modify that row which defeats my purpose. Also in case of locking, a column can only be locked in one mode i.e. either in READ or WRITE mode, which again fails to keep the data consistent as while reading a row it may get updated and the data which was just read would become an older version of what the table actually is right now. Is there a solid way to achieve this which can make sure that no request interferes with another and the table is in an updated state for the next incoming request? I am using MySQL with PHP if this helps.
Asked by FunnelScr (13 rep)
Jul 6, 2020, 03:14 AM
Last activity: Jul 6, 2020, 04:33 PM