X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 380EC54E34 for ; Fri, 4 Mar 2005 23:24:01 +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 34282-03 for ; Fri, 4 Mar 2005 23:23:58 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 8765A52A55 for ; Fri, 4 Mar 2005 23:23:56 +0000 (GMT) Received: (qmail 19932 invoked from network); 5 Mar 2005 00:24:45 +0100 Received: from unknown (HELO musicbox) (boutiquenumerique-lists@192.168.0.2) by boutiquenumerique.com with SMTP; 5 Mar 2005 00:24:45 +0100 To: "Thomas Mueller" , pgsql-sql@postgresql.org Subject: Re: Simple delete takes hours References: Message-ID: Date: Sat, 05 Mar 2005 00:24:00 +0100 From: PFC Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Opera M2/7.54u1 (Linux, build 892) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/71 X-Sequence-Number: 20550 Every time a row is removed from pwd_name, the ON DELETE CASCADE trigger will look in pwd_name_rev if there is a row to delete... Does it have an index on pwd_name_rev( rev_of ) ? If not you'll get a full table scan for every row deleted in pwd_name... On Thu, 03 Mar 2005 22:44:58 +0100, Thomas Mueller wrote: > Hi there, > > I have a simple database: > > CREATE TABLE pwd_description ( > id SERIAL NOT NULL UNIQUE PRIMARY KEY, > name varchar(50) NOT NULL > ); > > CREATE TABLE pwd_name ( > id SERIAL NOT NULL UNIQUE PRIMARY KEY, > description integer NOT NULL REFERENCES pwd_description(id), > name varchar(50) NOT NULL, > added timestamp DEFAULT now() > ); > > CREATE TABLE pwd_name_rev ( > id SERIAL NOT NULL UNIQUE PRIMARY KEY, > description integer NOT NULL REFERENCES pwd_description(id), > rev_of integer NOT NULL REFERENCES pwd_name(id) ON DELETE > CASCADE, > name varchar(50) NOT NULL > ); > > The indexes shouldn't matter I think. > > pwd_name_rev is filled by a stored procedure and a trigger (ON INSERT) > when something is inserted to pwd_name. Both tables contain about > 4.500.000 emtries each. > > I stopped 'delete from pwd_name where description=1' after about 8 hours > (!). The query should delete about 500.000 records. > Then I tried 'delete from pwd_name_rev where description=1' - this took > 23 seconds (!). > Then I retried the delete on pwd_name but it's running for 6 hours now. > > I use PostgreSQL 7.4.7 on Linux 2.6.10. The machine is a Celeron 2 GHz > with 512 MB RAM. > > PostgreSQL should do a full table scan I think, get all records with > description=1 and remove them - I don't understand what's happening for > >8 hours. > > > Any help is appreciated. > > > Thomas > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >