I know the difference between shared lock and exclusive lock.

But I am not able to figure out a use case when I should go for shared lock instead of exclusive lock. Because using exclusive lock and using normal select query select * from wmployee where id=4; serves the purpose of reading data when exclusive lock is applied.

So in which case should I be using shared lock? Please could someone explain with a MySQL example statement?

  • Why was it downvoted. It's a perfectly legit question. And there's still no answer yet. – KFL Oct 2 '19 at 0:23
  • I wonder the same question. My understand is that shared lock is useful in situations where a client need to use a set of rows in an extended period of time, it won't change them, but also requires them not to be changed by other parties during that period of time. However, I'm curious to see a real life example of this situation, which I can't think of one yet. – KFL Oct 2 '19 at 0:27

In general you should not worry about such. This pattern covers most common cases adequately.

SELECT ... FOR UPDATE; -- touch the rows you _might_ update
do some stuff
UPDATE ...;    -- then update them (or not)

Note that shared locks get 'promoted' in some circumstances for you.

If you would like to explain your situation we can be more specific.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.