Hi forum members,
I was wondering whether YugabyteDB supports optimistic locking?
If it does, I have the following questions:
What are the implementation details of it? Does the database read versions from cache or disk?
How does it impact write performance?
Hi @Ali_Zadehdehbalaei
See docs for locking: Explicit locking | YugabyteDB Docs
Depends if the data is already cached in-memory.
One of the transactions gets aborted and has to be retried by the client.
1 Like
Thanks for your reply @dorian_yugabyte .
Now I have quite a few new questions:
How can I use optimistic locking in Yugabyte DB?
Does it have a specific syntax or it will be handled manually and the database will only provides some constructs to speed up the process?
Is the “For Update” syntax used primarily for pessimistic locking or it can be used solely for optimistic locking as well?
Ali_Zadehdehbalaei:
How can I use optimistic locking in Yugabyte DB?
Does it have a specific syntax or it will be handled manually and the database will only provides some constructs to speed up the process?
It’s used by default.
See details Explicit locking | YugabyteDB Docs
1 Like
dorian_yugabyte:
It’s used by default.
Hi. I hope you are well.
I’m a new user of Yugabyte DB.
Does using optimistic locking cause read before write?
(If it causes read before write, therefore it reduces performance a lot. Am I right?)
It depends on the query and the full table schema + indexes.
1 Like