Subject Re: Deadlock @ Update
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, "mikcaau" wrote:
> --- In firebird-support@yahoogroups.com, Matthias Hanft wrote:
> >
> > Hello,
> >
> > I have a FB database where one record (always the same)
> > is updated very often (currently once per minute for
> > testing purposes; later perhaps once an hour). The SQL
> > command goes like this:
> >
> > update UPDATES
> > set DATETIME=:DATETIME, FILENAME=:FILENAME,
> > DATE_FROM=:DATE_FROM, DATE_TO=:DATE_TO
> > where ID=:ID;
> >
> > (This is surrounded by StartTransaction and Commit.)
> >
> > In 99,973% :-) this command succeeds. The rest raises
> > an exception "deadlock update conflicts with concurrent
> > update".
> >
> <snip>
> >
> Matt,
> You have to handle this in your application. Your app needs to
> detect the error, wait a while than try again.
> You would probably set a max tries before it gives up.
> Mick

Another option is simply to insert rather than update. If worrying
about the size of the table, it is just to do the occasional

DELETE FROM UPDATES U1
WHERE EXISTS(SELECT * FROM UPDATES U2 WHERE U2.ID = U1.ID AND
U2.DATETIMEFIELD > U1.DATETIMEFIELD)

In fact, you could do something like this with every insert if you
want. Admittedly, there is a 0.027% chance of duplicates in the ID
column ;o), but that shouldn't be too difficult to handle.

Set