X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 747989FA31F for ; Fri, 7 Jul 2006 18:59:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 90152-03 for ; Fri, 7 Jul 2006 18:59:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from bay0-omc2-s12.bay0.hotmail.com (bay0-omc2-s12.bay0.hotmail.com [65.54.246.148]) by postgresql.org (Postfix) with ESMTP id A46EA9FA6B2 for ; Fri, 7 Jul 2006 18:59:11 -0300 (ADT) Received: from hotmail.com ([65.54.229.32]) by bay0-omc2-s12.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 7 Jul 2006 14:59:09 -0700 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Fri, 7 Jul 2006 14:59:09 -0700 Message-ID: Received: from 65.54.229.220 by by110fd.bay110.hotmail.msn.com with HTTP; Fri, 07 Jul 2006 21:59:07 GMT X-Originating-IP: [69.236.161.187] X-Originating-Email: [xgoober99@hotmail.com] X-Sender: xgoober99@hotmail.com From: "K-Bob body" To: pgsql-performance@postgresql.org Subject: Delete is very slow; PG not using existing index to check foreign keys Date: Fri, 07 Jul 2006 16:59:07 -0500 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 07 Jul 2006 21:59:09.0456 (UTC) FILETIME=[92E90900:01C6A210] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/71 X-Sequence-Number: 19931 I've got a problem where Deletes on a certain table are taking very long (>5 sec) (PG 8.1.3, linux). Explain Analyze on the delete shows that two (automatically created) triggers caused by foreign keys are responsible for 99% of the time. * The two tables are large (>1.5mm and >400k rows), so sequential scans do take a long time. * I've got indices on these tables, but PG doesn't appear to be using them during the delete. * If I run the same SELECT in psql, it does use the index and responds very quickly. For example, I interrupted the Delete, and it appears that it was executing a select from an FK table: SELECT 1 FROM ONLY "public"."party_aliases" x WHERE "owner_party_id" = $1 FOR SHARE OF x; OK, that's fine. There's an index on that column: CREATE INDEX party_aliases_owner_party_idx ON party_aliases USING btree (owner_party_id, id); I've run ANALYZE, and that doesn't appear to make any difference. Why would PG use the index when I run the select myself, but do a sequential scan when the same statement is run by the delete trigger? I looked through the mailing lists, but most suggestions appeared to be 1) create an index, or 2) run analyze. Any ideas? Thanks in advance, Kian Wright _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/