Re: Summary table trigger example race condition

From: Mark Kirkwood <markir(at)paradise(dot)net(dot)nz>
To: Mark Kirkwood <markir(at)paradise(dot)net(dot)nz>
Cc: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>, pgsql-patches(at)postgresql(dot)org, pgsql-docs(at)postgresql(dot)org
Subject: Re: Summary table trigger example race condition
Date: 2006-01-08 03:13:01
Message-ID: 43C0833D.4040607@paradise.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-patches

Mark Kirkwood wrote:
> Jim C. Nasby wrote:
>
>> On Fri, Jan 06, 2006 at 02:00:34PM +1300, Mark Kirkwood wrote:
>>
>>> However, I think the actual change is not quite right - after running
>>
>>
>>
>> DOH! It would be good if doc/src had a better mechanism for handling
>> code; one that would allow for writing the code natively (so you don't
>> have to worry about translating < into &lt; and > into &gt;) and for
>> unit testing the different pieces of code.
>>
>
> Yes it would - I usually build the SGML -> HTML, then cut the code out
> of a browser session to test - the pain is waiting for the docs to build.
>
>> Anyway, updated patch attached.
>>
>
> This one is good!
>

After re-examining the original code, it looks like it was not actually
vulnerable to a race condition! (it does the UPDATE, then if not found
will do an INSERT, and handle unique violation with a repeat of the same
UPDATE - i.e three DML statements, which are enough to handle the race
in this case).

However Jim's change handles the race needing only two DML statements in
a loop, which seems much more elegant! In addition it provides a nice
example of the 'merge' style code shown in e.g 36-1.

Cheers

Mark

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-11 00:09:51 Re: [PATCHES] Summary table trigger example race condition
Previous Message Mark Kirkwood 2006-01-06 03:46:26 Re: Summary table trigger example race condition

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2006-01-08 03:59:27 Re: psql tab completion enhancements
Previous Message Joachim Wieland 2006-01-07 19:18:12 Re: CIDR/INET improvements