Concurrency, Rails and PostgreSQL vs. MySQL

Hi,

Let’s say we have users concurrently performing the following queries
inside a transaction (example taken directly from PostgreSQL site):

User A:

BEGIN;
UPDATE accounts SET balance = balance + 100.00 WHERE acctnum = 12345;

COMMIT;

User B:

BEGIN;

UPDATE accounts SET balance = balance + 100.00 WHERE acctnum = 12345;

COMMIT;

Am I right assuming that in case of PostgreSQL the UPDATE query of User
B would be working with an updated version of the accounts row, whereas
in case of MySQL it would update the original one?

If I use rails’ optimistic locking feature, I would ensure
database-independent behaviour, but would have to implement the
handling of rolled-back transactions on my own, right?

Are there any best practices for concurrency control with rails out
there?

I am quite new to this subject, so please bear with me in case I am
being ignorant :wink:

Thanks in advance,

Alexei

On 8/24/06, Alexei M. [email protected] wrote:

there?

I am quite new to this subject, so please bear with me in case I am
being ignorant :wink:

Alexei, I believe this is the same message you posted two days ago. Did
you
see the replies?

In short: both databases do what you expect. Use a single update
statement
to avoid issues with concurrency, locking, and dirty reads.

Best,
jeremy

Alexei, I believe this is the same message you posted two days ago. Did you
see the replies?

Yes, I’ve seen the replies - I have no idea, why the same message got
posted once again, days later :confused:

Thank you very much for your help!

Alexei