X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CD72053492 for ; Fri, 25 Mar 2005 01:44:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38051-09 for ; Fri, 25 Mar 2005 01:44:48 +0000 (GMT) Received: from mailgate2.nau.edu (mailgate2.nau.edu [134.114.96.59]) by svr1.postgresql.org (Postfix) with ESMTP id D00FF52A76 for ; Fri, 25 Mar 2005 01:44:47 +0000 (GMT) Received: from CONVERSION-DAEMON.mailgate2.nau.edu by mailgate2.nau.edu (PMDF V6.2-X17 #30770) id <0IDV00H01WUQAW@mailgate2.nau.edu> for pgsql-performance@postgresql.org; Thu, 24 Mar 2005 18:44:50 -0700 (MST) Received: from k2.cet.nau.edu (net9-213.cet.nau.edu [134.114.9.213]) by mailgate2.nau.edu (PMDF V6.2-X17 #30770) with ESMTP id <0IDV00C9ZWUPR7@mailgate2.nau.edu> for pgsql-performance@postgresql.org; Thu, 24 Mar 2005 18:44:49 -0700 (MST) Date: Thu, 24 Mar 2005 18:48:24 -0700 From: Karim Nassar Subject: Re: Delete query takes exorbitant amount of time In-reply-to: <2630.1111711927@sss.pgh.pa.us> To: pgsql-performance@postgresql.org Message-id: <1111715304.9089.179.camel@k2.cet.nau.edu> MIME-version: 1.0 X-Mailer: Evolution 2.0.2 Content-type: text/plain Content-transfer-encoding: 7BIT References: <1111709457.9085.127.camel@k2.cet.nau.edu> <2630.1111711927@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/529 X-Sequence-Number: 11234 On Thu, 2005-03-24 at 19:52 -0500, Tom Lane wrote: > Karim Nassar writes: > > Here is the statement: > > > orfs=# explain analyze DELETE FROM int_sensor_meas_type WHERE > > id_meas_type IN (SELECT * FROM meas_type_ids); > > QUERY PLAN > > ----------------------------------------------------------------------------------------------------------------------------- > > Hash Join (cost=11.53..42.06 rows=200 width=6) (actual > > time=1.564..2.840 rows=552 loops=1) > > ... > > Total runtime: 2499616.216 ms > > (7 rows) > > Notice that the actual join is taking 2.8 ms. The other ~40 minutes is > in operations that we cannot see in this plan, but we can surmise are ON > DELETE triggers. There are no DELETE triggers (that I have created). > > Where do I go from here? > > Look at what your triggers are doing. My private bet is that you have > unindexed foreign keys referencing this table, and so each deletion > forces a seqscan of some other, evidently very large, table(s). Almost. I have a large table (6.3 million rows) with a foreign key reference to this one (which has 749 rows), however it is indexed. I deleted the fk, ran the delete, then recreated the foreign key in about 15 seconds. Thanks! Problem now is: this referencing table I expect to grow to about 110 million rows in the next 2 months, then by 4 million rows per month thereafter. I expect that the time for recreating the foreign key will grow linearly with size. Is this just the kind of thing I need to watch out for? Any other suggestions for dealing with tables of this size? What can I do to my indexes to make them mo' betta? -- Karim Nassar Department of Computer Science Box 15600, College of Engineering and Natural Sciences Northern Arizona University, Flagstaff, Arizona 86011 Office: (928) 523-5868 -=- Mobile: (928) 699-9221