I am trying to find out, what the difference between optimistic concurrency control (OCC) and multi version concurrency control (MVCC) is?
So far I know that both is based on version checking for updates.
In OCC, I read about transactions that acquire no locks for reading access, only for the later update which will fail if in between the version was incremented and version checking fails. In this case the transaction will be rolled back.
In MVCC, it is basically the same, or not? Where is the difference?
To directly reply to the question, multi version concurrency control (MVCC) is a concurrency control method, (typically) belonging in the category of optimistic concurrency control (OCC).
There are 2 main concurrency control approaches:
One widely known algorithm of pessimistic concurrency control is the 2-phase locking.
Two widely known algorithms of optimistic concurrency control are:
The main difference between these 2 algorithms is the following. The timestamp-based algorithm assigns a single (more correctly one for each kind of operation, read & write) timestamp to each object, denoting the last transaction that accessed it. So, each transaction checks during the operation, if it conflicts with the last transaction that accessed the object. The multi-version approach maintains multiple versions of each object, each one corresponding to a transaction. As a result, the multi-version approach manages to have fewer aborts than the first approach, since a potentially conflicting transaction can write a new version, instead of aborting in some cases. However, this is achieved at the cost of more storage required for all the versions.
Strictly speaking, MVCC is concerned mostly with how data are stored, i.e. the fact that there can be multiple physical versions for each data item. As a result, it is theoretically possible to combine it with pessimistic methods as well(e.g. locking), but its multi-version nature is best combined with optimistic methods.