X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 437A89DC815; Sat, 7 Jan 2006 23:15:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30770-08; Sat, 7 Jan 2006 23:15:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-5.paradise.net.nz (bm-5a.paradise.net.nz [203.96.152.184]) by postgresql.org (Postfix) with ESMTP id 339B99DCB8E; Sat, 7 Jan 2006 23:15:42 -0400 (AST) Received: from smtp-1.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-5.paradise.net.nz (Paradise.net.nz) with ESMTP id <0ISR00M6G7LRBG@linda-5.paradise.net.nz>; Sun, 08 Jan 2006 16:13:04 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-194.dsl.clear.net.nz [218.101.28.194]) by smtp-1.paradise.net.nz (Postfix) with ESMTP id 6621853916D; Sun, 08 Jan 2006 16:13:03 +1300 (NZDT) Date: Sun, 08 Jan 2006 16:13:01 +1300 From: Mark Kirkwood Subject: Re: Summary table trigger example race condition In-reply-to: <43BDE812.5000103@paradise.net.nz> To: Mark Kirkwood Cc: "Jim C. Nasby" , pgsql-patches@postgresql.org, pgsql-docs@postgresql.org Message-id: <43C0833D.4040607@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: <20060105213645.GY43311@pervasive.com> <43BDC132.90007@paradise.net.nz> <20060106030415.GL43311@pervasive.com> <43BDE812.5000103@paradise.net.nz> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.296 required=5 tests=[AWL=0.296] X-Spam-Score: 0.296 X-Spam-Level: X-Archive-Number: 200601/94 X-Sequence-Number: 18430 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 < and > into >) 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