Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0553765B127 for ; Tue, 16 Mar 2010 19:15:05 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 31264-06 for ; Tue, 16 Mar 2010 22:14:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.pcl-ipout02.plus.net (relay.pcl-ipout02.plus.net [212.159.7.100]) by mail.postgresql.org (Postfix) with ESMTP id 3AEBD6344E8 for ; Tue, 16 Mar 2010 19:14:54 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAEufn0tUXebi/2dsb2JhbACbBXO6Y4R2BA Received: from relay03.plus.net ([84.93.230.226]) by relay.pcl-ipout02.plus.net with ESMTP; 16 Mar 2010 22:14:52 +0000 Received: from [84.51.143.99] (helo=server3.office.archonet.com) by relay03.plus.net with esmtp (Exim) id 1Nrf2K-0001VM-5q; Tue, 16 Mar 2010 22:14:52 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTPA id DC8B2274091; Tue, 16 Mar 2010 22:14:51 +0000 (GMT) Message-ID: <4BA002DC.1050700@archonet.com> Date: Tue, 16 Mar 2010 22:14:52 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9pre) Gecko/20100217 Lightning/1.0b1 Shredder/3.0.3pre MIME-Version: 1.0 To: Tom Lane CC: Tony Cebzanov , pgsql-sql@postgresql.org Subject: Re: Avoiding cycles in a directed graph References: <4B9FDFDE.5030005@andrew.cmu.edu> <4B9FE752.4080709@archonet.com> <14113.1268771643@sss.pgh.pa.us> <4B9FEEE8.1060404@andrew.cmu.edu> <14550.1268773752@sss.pgh.pa.us> In-Reply-To: <14550.1268773752@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 01f834b92787ac12a119285a1734ea7a X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.154 tagged_above=-10 required=5 tests=AWL=0.445, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/116 X-Sequence-Number: 33823 On 16/03/10 21:09, Tom Lane wrote: > Tony Cebzanov writes: >> I'm okay with running the big, fat WITH RECURSIVE query in my insert >> trigger if I have to -- it won't be great for performance, but I don't >> expect this to be a frequent operation, so I'll accept the performance >> hit if it works. > >> Unfortunately I can't even get that working. Here's the (not at all >> functional) trigger I've got right now, which only detects the cycle >> *after* it's been inserted, which is of no help at all. Any way I can >> modify this to do the right thing? > > Run it in an AFTER trigger? > > If you don't expect this to be common, maybe you could fix the > concurrency issue by taking a table-wide lock that locks out > other writers. Surely SELECT FOR UPDATE on the parents would be sufficient? If there's no overlap between (currently non-cyclic) graphs being altered then there can't be any conflict. -- Richard Huxton Archonet Ltd