Mysql doesn't auto lock or version lock records when select
in repeatable read
transactions. While PG can forbid concurrent updates.
The test table DDL in PG:
create table articles (
"id" serial,
"n" integer
);
For mysql to avoid race conditions, there are 3 ways:
- (pessimistic lock)
select ... for lock in share mode
in transaction - (pessimistic lock)
select ... for upadte
in transaction and other places that updates the record(s) - (optimistic lock) use optimistic locks that can cause a phantom read -- then it will forbid the update
PG transacions (note that PG does avoid phantom reads, see the paragraph after the table of ISO isolation definition table):
http://www.postgresql.org/docs/9.1/static/transaction-iso.html
Edit: this example is not phantom read, just a pitfall of repeatable reads in mysql