From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Markus Wanner <markus(at)bluegap(dot)ch>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: determine snapshot after obtaining locks for first statement |
Date: | 2009-12-17 18:07:55 |
Message-ID: | 603c8f070912171007g39c57d9dibc37a64df4eb408d@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Dec 17, 2009 at 1:05 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> I'm not very sure what a clearer explanation would look like
>
>> As a stab at it, how about?:
>
>> This behavior makes Read Committed mode unsuitable for many UPDATE
>> or DELETE commands with joins or subqueries
>
> After thinking a bit, I'd be inclined to add a new paragraph.
> In particular, now that FOR UPDATE actually works in subqueries,
> it'd be worth pointing out that you can add that to guard against
> this type of issue. Perhaps, after the "DELETE FROM website"
> example, we could add something like
>
> UPDATEs and DELETEs involving joins or subqueries are particularly
> at risk, since they may perform an update based on a combination of
> old rows from other tables with an up-to-date target row. This risk
> can be mitigated by adding FOR UPDATE or FOR SHARE to subqueries, so
> that all rows directly involved in an update are guaranteed current.
> However that will also increase the risk of deadlock failures.
I like that. It might also be worth trying to explain that if you
select some data out of the database, do a computation with it, and
then use the results to drive an update, you're going to want to make
the initial select be FOR SHARE.
...Robert
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2009-12-17 18:12:02 | Re: determine snapshot after obtaining locks for first statement |
Previous Message | Tom Lane | 2009-12-17 18:05:51 | Re: determine snapshot after obtaining locks for first statement |