Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 22CFCB5DBC4 for ; Wed, 28 Sep 2011 11:30:05 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 36141-07 for ; Wed, 28 Sep 2011 14:29:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from imx3.etecsa.cu (imx3.etecsa.cu [200.55.152.137]) by mail.postgresql.org (Postfix) with ESMTP id BC43DB5DC1C for ; Wed, 28 Sep 2011 11:29:56 -0300 (ADT) Received: from Unknown ([192.168.91.42] helo=mn2.etecsa.cu) by imx3.etecsa.cu with ESMTP id pATbHeMr34347; Wed, 28 Sep 2011 10:29:37 -0500 Received: (qmail 8679 invoked by uid 11185); 28 Sep 2011 15:29:37 -0000 Received: from 192.168.219.193 by mn2.etecsa.cu (envelope-from , uid 502) with qmail-scanner-2.08 (spamassassin: 3.2.5. Clear:RC:1(192.168.219.193):. Processed in 0.022681 secs); 28 Sep 2011 15:29:37 -0000 Received: from unknown (HELO [192.168.219.193]) (gilberto.castillo@[192.168.219.193]) (envelope-sender ) by mn3.etecsa.cu (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 28 Sep 2011 15:29:37 -0000 Subject: Re: constraint triggers From: Gilberto Castillo =?ISO-8859-1?Q?Mart=EDnez?= Reply-To: gilberto.castillo@etecsa.cu To: Maria.L.Wilson-1@nasa.gov Cc: "pgsql-admin@postgresql.org" In-Reply-To: <4E83190B.3070604@nasa.gov> References: <4E83190B.3070604@nasa.gov> Organization: ETECSA Date: Wed, 28 Sep 2011 10:26:29 -0400 Message-Id: <1317219989.24926.10.camel@gilbertoc.mtcorp.etecsa.cu> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-19.el5) X-SpamTest-Envelope-From: gilberto.castillo@etecsa.cu X-SpamTest-Info: Profiles 25263 [Sep 28 2011] X-SpamTest-Info: {DNSBL Rate: low} X-SpamTest-Method: none X-SpamTest-Rate: 20 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0285], KAS30/SDK/Release X-Anti-Virus: Kaspersky Mail Gateway, version: 5.6.28/RELEASE, bases: 20110928T044526 #5482750, check: 20110928 clean Content-Type: multipart/mixed; boundary="=pATcHuKt52770=imx3.etecsa.cu=" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/207 X-Sequence-Number: 38444 This is a multi-part message in MIME format. --=pATcHuKt52770=imx3.etecsa.cu= Content-Disposition: inline Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit El mié, 28-09-2011 a las 08:54 -0400, Maria L. Wilson escribió: > Hi all.... > > I would like to start a dialogue and hear general feedback about the > use of constraint triggers in postgres (8.4.5). > > Our overall issue is that using general triggers is causing slow > inserts (from locking issues) in our database. Here are some details: > > A little background (jboss/j2ee/hibernate/linux)..... > We have 3 basic triggers on a particular database table - one for > inserts, one for updates & another for deletes and they keep track of > a "granule count" that is used in reporting. This field (gracount) is > stored in another table called dataset. An example of the insert > trigger/function is as follows: > > ---------------------- > CREATE TRIGGER increment_dataset_granule_count > AFTER INSERT > ON inventory > FOR EACH ROW > EXECUTE PROCEDURE increment_dataset_granule_count(); > > CREATE OR REPLACE FUNCTION increment_dataset_granule_count() > RETURNS trigger AS > $BODY$ > DECLARE > BEGIN > IF NEW.visible_id != 5 THEN > UPDATE dataset > SET gracount = gracount + 1 > WHERE dataset.inv_id = NEW.inv_id; > END IF; > RETURN NULL; > END; > $BODY$ > LANGUAGE plpgsql VOLATILE > COST 100; > ALTER FUNCTION increment_dataset_granule_count() OWNER TO jboss; > ----------------------- Replace RETURN NULL for RETURN NEW -- Saludos, Gilberto Castillo Edificio Beijing. Miramar Trade Center. Etecsa. Miramar, La Habana.Cuba. --=pATcHuKt52770=imx3.etecsa.cu= Content-Type: text/plain Content-Disposition: inline --- This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu Visit our web-site: , --=pATcHuKt52770=imx3.etecsa.cu=--