NOTE
Database Optimistic Locking and Pessimistic Locking
1. Pessimistic Locking 2. Optimistic Locking Optimistic locking assumes that data conflicts generally will not occur, so conflicts are formally detected only when data is submitted for update. Version Number Add a version field. Query once first. When updating, add update xxx set version=version+1 where version=version to the original statement; if it fails, loop and retry. 3. Reference Database First-Type and Second-Type Lost Updates - Tencent Cloud
This is a historical learning note and may contain outdated or incomplete understanding.
1. Pessimistic Locking
select aaa from bbb where aaa=ccc for update
2. Optimistic Locking
Optimistic locking assumes that data conflicts generally will not occur, so conflicts are formally detected only when data is submitted for update.
- Version number
- Add a
versionfield. Query once first. When updating, addupdate xxx set version=version+1 where version=versionto the original statement; if it fails, loop and retry.
- Add a
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub