3

This question is a logical continuation of this one:

How many rows will be locked by SELECT ... ORDER BY xxx LIMIT 1 FOR UPDATE?

Suppose I have such SELECT:

SELECT id, status FROM job WHERE status = XXX AND id IN (1, 2, 3) FOR UPDATE

id is primary key, status is indexed.

What's MySQL locking strategy in this case?

  1. Lock rows matching only both conditions
  2. Lock all rows matching first condition + lock all rows matching the second condition separately
  3. Lock the whole table

I think the most logical is 2. But... I'm not sure. Can you elaborate?

Community
  • 1
  • 1
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156

1 Answers1

1

Well, I made tests and they show that option 1 is in effect in this case.

Lock rows matching only both conditions

Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156