1

Is there any significant difference in performance in using PESSIMISTIC_WRITE as LockMode in hibernate criteria as an alternative for Select for update query.

Use case involves following points:

  1. Restrictions on values in multiple columns like status, time
  2. Sorting on multiple columns
  3. Select only the first row for processing.

This processing is done simultaneously by multiple machines/threads. I am currently using hibernate criteria, and that is causing timeouts in getting lock multiple times, which results in choking of all other queries.

1 Answers1

0

In this case, the FOR UPDATE is "required" for proper concurrency:

BEGIN;
SELECT x ... FROM t ... FOR UPDATE;
use `x` for whatever
UPDATE t ...;
COMMIT;

Without FOR UPDATE, the value of x could change, thereby potentially invalidating the intent of the UPDATE.

Rick James
  • 135,179
  • 13
  • 127
  • 222