[CDBI] atomic find_or_create()
[prev]
[thread]
[next]
[Date index for 2005/10/22]
Has anyone ever tried to make an atomic version of find_or_create()?
The existing version has a race condition in that someone else could
create a record with the specified primary key in between the SELECT and
INSERT.
I need this on MySQL InnoDB and I was considering a couple of
strategies. The most obvious one is to lock the table (in shared mode)
while doing the normal find_or_create(). Less obvious would be to use
INSERT IGNORE followed by a SELECT. This could cause strange results if
you pass in search criteria that don't form a unique key, but that's
true for the existing method anyway.
Anyone else have thoughts on this?
- Perrin
_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
|
[CDBI] atomic find_or_create()
Perrin Harkins 00:33 on 22 Oct 2005
|