X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D79AB9DCA28 for ; Mon, 6 Feb 2006 08:48:21 -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 52079-06 for ; Mon, 6 Feb 2006 08:48:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ibox-server.openwired.net (77.Red-213-97-52.staticIP.rima-tde.net [213.97.52.77]) by postgresql.org (Postfix) with ESMTP id 2CA349DC994 for ; Mon, 6 Feb 2006 08:48:18 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ibox-server.openwired.net (Postfix) with ESMTP id 246382E01DD for ; Mon, 6 Feb 2006 13:36:49 +0000 (GMT) Received: from ibox-server.openwired.net ([127.0.0.1]) by localhost (ibox-server.openwired.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26380-04 for ; Mon, 6 Feb 2006 13:36:47 +0000 (GMT) Received: from [10.0.0.21] (unknown [10.0.0.21]) by ibox-server.openwired.net (Postfix) with ESMTP id 529FF2E01D2 for ; Mon, 6 Feb 2006 13:36:47 +0000 (GMT) Message-ID: <43E74594.5040209@openwired.net> Date: Mon, 06 Feb 2006 13:48:20 +0100 From: =?ISO-8859-1?Q?Josep_Sanmart=ED?= User-Agent: Mozilla Thunderbird 1.0.5 (X11/20050711) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Trigger efficiency Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by I-Box de Openwired (www.openwired.com) Antivirus-Antispam at openwired.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.733 required=5 tests=[AWL=-0.418, RCVD_IN_WHOIS_INVALID=2.151] X-Spam-Score: 1.733 X-Spam-Level: * X-Archive-Number: 200602/49 X-Sequence-Number: 24059 Hi, I've the following problem and I don't know how to solve it: There is a table with about 10-12 fields, a couple of those fields are updated very often (about 30 times / minute or even more). This is my table (more or less): crete table monitor( time Timestamp, time2 timestamp, ... status int, ); I need to know how many rows are in the table and keep that number to another table every time that there is an INSERT or DELETE on that table, so I made a trigger that fires on insert and delete events and calls a function that makes de update on the new table, that works well. My problem starts when I have to count the rows depending on the status field: I added a UPDATE on my trigger and it works! :)...... my trigger: CREATE TRIGGER tr_barra_aps AFTER INSERT OR DELETE OR UPDATE ON monitor EXECUTE PROCEDURE f_barra_aps(); But now, this trigger fires too often and there is an extra load on the system that makes everything run slower. I posted before a question asking about firing triggers on specific columns...thats not possible. I don't know how to solve it, perhaps I should do it without triggers.....any help will be appreciated thanks! -- Josep Sanmarti Analista de Projectes OpenWired Caballero 87 - Bajos 08029 - Barcelona Tel. 93 495 0990 Fax. 93 419 4591 Openwired Alejandro Villegas,29 28043 - MADRID - ESPAÑA Teléfono: 91 300 51 09 Fax: 91 300 28 13 http://www.openwired.com