Hi,

Let say that I have the following transaction:

1. Read value v1 from table t1.
2. Do some computation using v1.
3. Update value v2 from table t2.

If in the above I don't want any other concurrent transaction to read v2 until I'm done updating it, how should I put an exclusive lock on it?

Using InnoDB, would the following be the way to do it (in transaction mode, seriliazable isolation level)?

SELECT v2 from t2 FOR UPDATE; // (Do this to prevent others from reading v2)

SELECT v1 from t1;

(do the computation)

UPDATE t2 set v2=<new value>;

COMMIT;


In the above statements, I first read the value v2 to put an exclusive lock on that row. But I don't really need the value of v2, I just need to lock it down. Is the above approach the way to go or is there a more elegant/correct way of doing this?


Thanks.
--
Andre Charbonneau



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to