Re: Summary table trigger example race condition

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

Jim C. Nasby wrote:
> On Sun, Jan 08, 2006 at 04:13:01PM +1300, Mark Kirkwood wrote:
>
>>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).
>
>
> What happens if someone deletes the row between the failed insert and
> the second update? :)
>

In this example the rows in the summary table never get deleted by
DELETE operations on that main one - the trigger just decrements the
various amounts - i.e DELETE becomes UPDATE, so no problem there.

> AFAICT, example 36-1 is the only way to handle this without creating a
> race condition.
>

For the general case indeed you are correct - a good reason for this
change :-). In addition, that fact that it is actually quite difficult
to be sure that any race condition is actually being handled makes
(another) good reason for using the most robust method in the 'official'
examples.

Best wishes

Mark

In response to

Responses

Browse pgsql-docs by date

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

Browse pgsql-patches by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-11 00:44:17 Re: TODO-item: Add sleep() function, remove from regress.c
Previous Message Jim C. Nasby 2006-01-11 00:09:51 Re: [PATCHES] Summary table trigger example race condition