Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 38AD89F9EEC for ; Thu, 2 Nov 2006 19:51:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 06245-06 for ; Thu, 2 Nov 2006 19:51:04 -0400 (AST) X-Greylist: delayed 00:33:10.401748 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id ADAC19FA3B1 for ; Thu, 2 Nov 2006 19:51:03 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from beast.liquidweb.com (beast.liquidweb.com [64.91.224.2]) by svr4.postgresql.org (Postfix) with ESMTP id 2E6335AF896 for ; Thu, 2 Nov 2006 23:17:51 +0000 (GMT) Received: from c-24-11-214-165.hsd1.mi.comcast.net ([24.11.214.165]:60166 helo=[10.2.1.2]) by beast.liquidweb.com with esmtpsa (TLSv1:RC4-MD5:128) (Exim 4.52) id 1Gflot-0001p6-3W; Thu, 02 Nov 2006 18:17:59 -0500 Message-ID: <454A7C9B.40207@intellicon.biz> Date: Thu, 02 Nov 2006 18:17:47 -0500 From: Benjamin Minshall Organization: Intellicon, Inc. User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: robins@pobox.com Cc: pgsql-performance@postgresql.org Subject: Re: Locking vs. Exceptions References: <36af4bed0611020445s445e3fe8o344f529190a8dfea@mail.gmail.com> In-Reply-To: <36af4bed0611020445s445e3fe8o344f529190a8dfea@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ClamAntiVirus-Scanner: This mail is clean X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - beast.liquidweb.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - intellicon.biz X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.014 tagged_above=0 required=5 tests=BAYES_50, BIZ_TLD X-Spam-Level: ** X-Archive-Number: 200611/33 X-Sequence-Number: 21803 Robins wrote: > Hi, > > The documentation says that function blocks with exceptions are far > costlier than without one. > I recommend against using exceptions. There is a memory leak in the exception handler that will cause headaches if it is called many times in the transaction. In plpgsql, I would use: SELECT ... FOR UPDATE; IF FOUND THEN UPDATE ...; ELSE INSERT ...; END IF; If you have multiple transactions doing this process at the same time, you'll need explicit locking of the table to avoid a race condition. -- Benjamin Minshall Senior Developer -- Intellicon, Inc. http://www.intellicon.biz