Re: Implicit row locking during an UPDATE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dr(dot) Evil" <drevil(at)sidereal(dot)kz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Implicit row locking during an UPDATE
Date: 2001-05-25 04:45:32
Message-ID: 4305.990765932@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Dr. Evil" <drevil(at)sidereal(dot)kz> writes:
> From my understanding, this:

> UPDATE account SET value = 10 WHERE number = 99;

> actually implies all of this:

> BEGIN;
> SELECT value FOR UPDATE FROM account WHERE number = 99;
> UPDATE account SET value = 10 WHERE number = 99;
> COMMIT;
> END;

Not really. Plain UPDATE doesn't lock the target tuple in advance of
computing the new version; it optimistically assumes that it doesn't
need to do that. If that turns out to be wrong when it actually goes
to update the tuple, it backs off, recomputes the update, and tries
again. Normally this ends up at the same place as your two-step
example, but not when the UPDATE targetlist has side effects...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karen Ellrick 2001-05-25 05:25:44 RE: Install with Apache/PHP (Was "Stubborn Multibyte")
Previous Message Eric G. Miller 2001-05-25 04:25:43 Re: Implicit row locking during an UPDATE