|
|||||||||||
|
Re: [GENERAL] Locking & concurrency - best practices
From: Adam Rich <adam.r(at)indigodynamic.com>
Date: Mon Jan 14 2008 - 16:31:00 EST
I don't think that will work. Let me demonstrate: (this is simplified, but sufficient to make my point)
select * from parent_tbl
select count(*) into myvar
if (myvar < 3) then
update parent_tbl
update parent_tbl
commit;
begin trans; insert into data_tbl (fk, data) values (1, 'foo'); insert into data_tbl (fk, data) values (1, 'bar'); insert into data_tbl (fk, data) values (1, 'baz');commit;
In what way would you use "FOR UPDATE" on data_tbl to ensure parent_tbl doesn't end up with the wrong status ? AFAIK, "FOR UPDATE" locks only the rows returned, and does nothing to prevent new inserts. using a "serialized" isolation doesn't seem appropriate either. As far as I can tell, the only options are locking the entire data_tbl at the start of both connections (which unfortunately also blocks all other transactions with id/fk != 1), or using advisory locks.
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Received on Mon Jan 14 16:35:01 2008This archive was generated by hypermail 2.1.8 : Tue Jun 17 2008 - 00:12:23 EDT |
||||||||||
|
|||||||||||