Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 41C769FB69F for ; Tue, 10 Apr 2007 10:54:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 12403-01 for ; Tue, 10 Apr 2007 10:54:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 56D7C9FB33F for ; Tue, 10 Apr 2007 10:54:05 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l3ADs2oe025201; Tue, 10 Apr 2007 09:54:02 -0400 (EDT) To: Drew Wilson cc: pgsql-performance@postgresql.org Subject: Re: how to efficiently update tuple in many-to-many relationship? In-reply-to: References: <233A9987-ABA5-4491-A304-FDA1F8FCD962@gmail.com> <14019.1176155022@sss.pgh.pa.us> <22512E5C-A60F-43E7-A370-257F7AF956FD@gmail.com> <16374.1176171185@sss.pgh.pa.us> Comments: In-reply-to Drew Wilson message dated "Mon, 09 Apr 2007 22:46:29 -0700" Date: Tue, 10 Apr 2007 09:54:02 -0400 Message-ID: <25200.1176213242@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/228 X-Sequence-Number: 24105 Drew Wilson writes: > The SELECT is not slow, so its a side effect of the update... Looking > at the table definition, there is a "BEFORE ON DELETE" trigger > defined, two CHECK constraints for this table, and three foreign > keys. Nothing looks suspicious to me. Since this is an update we can ignore the before-delete trigger, and the check constraints don't look expensive to test. Outgoing foreign key references are normally not a problem either, since there must be an index on the other end. But *incoming* foreign key references might be an issue --- are there any linking to this table? Also, the seven indexes seem a bit excessive. I'm not sure if that's where the update time is going, but they sure aren't helping, and some of them seem redundant anyway. In particular I think that the partial index WHERE obsolete IS NOT TRUE is probably a waste (do you have any queries you know use it? what do they look like?) and you probably don't need all three combinations of source_id and translation_id --- see discussion here: http://www.postgresql.org/docs/8.2/static/indexes-bitmap-scans.html BTW, I don't think you ever mentioned what PG version this is exactly? If it's 8.1 or later it would be worth slogging through EXPLAIN ANALYZE on the update, or maybe an update of 10% or so of the rows if you're impatient. That would break out the time spent in the triggers, which would let us eliminate them (or not) as the cause of the problem. regards, tom lane