0

I am using mysql + php for my web application and I am using sql locks to make sure that multiple instances of my php script select different rows from a mysql table.

What I need to ask is, if I am locking few rows of a table using FOR UPDATE clause, and the other instance use the same query, which is a simple select statement with ORDER BY and LIMIT clause, will the second instance select the next rows skipping the locked rows or will it wait for the first instance transaction to be completed?

I want that it should just skip the rows which are locked and retrieve next set of rows from the table. For example, I have a sql table with users and a column user_LastUpdated with timestamp

My query would be something like

SELECT * FROM users ORDER BY user_LastUpdated LIMIT 5 FOR UPDATE

If the users table have huge amount of rows, can two instances running the above query return simultaneous results?

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
  • Do you mind sharing what you're trying to do? We might be able to suggest a better design. – Samuel Aug 13 '15 at 13:11
  • Thanks for the quick reply. @Samuel You are correct the link you have given is doing the same thing but is this the correct way to do it? I mean keeping a process id for every table on which i might want to do the same thing? – Satinder Rana Aug 13 '15 at 13:18

0 Answers0