What is the difference between optimistic and pessimistic locking?
Model answer
Pessimistic locking locks rows when reading (SELECT ... FOR UPDATE) so others wait. Optimistic locking does not lock, but stores a version number or timestamp and fails the update if it changed since you read it, so you retry. Optimistic works well when conflicts are rare.
Learn this topic
Indexes and Faster Queries: EXPLAIN for Beginners in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.