Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id ABFF4650138 for ; Thu, 7 Aug 2008 11:36:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 69255-01 for ; Thu, 7 Aug 2008 11:36:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail2.ttmail.com (unknown [88.255.235.9]) by postgresql.org (Postfix) with ESMTP id 8FE42650115 for ; Thu, 7 Aug 2008 11:36:41 -0300 (ADT) Received: from SMTP2 ([192.168.19.137]) by mail2.ttmail.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 7 Aug 2008 17:36:38 +0300 Received: from alamut.mobiliz.com.tr ([213.139.194.86]) by SMTP2 with Microsoft SMTPSVC(6.0.3790.1830); Thu, 7 Aug 2008 17:36:37 +0300 Received: from (unknown [213.139.194.86]) by AVGW-TTMAIL-5.ttmail.com with smtp id 3da3_38ca4fea_648e_11dd_975a_0011433771ac; Thu, 07 Aug 2008 17:36:36 +0300 From: Volkan YAZICI To: Richard Huxton Cc: pgsql-performance@postgresql.org Subject: Re: Unexpectedly Long DELETE Wait References: <874p5xwe3g.fsf@alamut.mobiliz.com.tr> <489AAB08.9080409@archonet.com> Date: Thu, 07 Aug 2008 17:36:28 +0300 In-Reply-To: <489AAB08.9080409@archonet.com> (Richard Huxton's message of "Thu, 07 Aug 2008 08:58:00 +0100") Message-ID: <877iasvqmr.fsf@alamut.mobiliz.com.tr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-NAI-Spam-Report: 1 Rules triggered * 0 -- RV3076 -- BODY: Version number X-OriginalArrivalTime: 07 Aug 2008 14:36:37.0862 (UTC) FILETIME=[FFB2D060:01C8F89A] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.1 tagged_above=0 required=5 tests=RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200808/41 X-Sequence-Number: 30922 On Thu, 07 Aug 2008, Richard Huxton writes: > Volkan YAZICI wrote: >> DELETE FROM mugpsreglog >> WHERE NOT EXISTS (SELECT 1 >> FROM mueventlog >> WHERE mueventlog.eventlogid = mugpsreglog.eventlogid); >> >> Seq Scan on mugpsreglog (cost=0.00..57184031821394.73 rows=6590986 width=6) >> Filter: (NOT (subplan)) >> SubPlan >> -> Seq Scan on mueventlog (cost=0.00..4338048.00 rows=1 width=0) >> Filter: (eventlogid = $0) > > Ouch - look at the estimated cost on that! > >> And there isn't any constraints (FK/PK), triggers, indexes, etc. on any >> of the tables. (We're in the phase of a migration, many DELETE commands >> similar to above gets executed to relax constraints will be introduced.) > > Well there you go. Add an index on eventlogid for mugpsreglog. Hrm... Adding an INDEX on "eventlogid" column of "mueventlog" table solved the problem. Anyway, thanks for your kindly help. > Alternatively, if you increased your work_mem that might help. Try SET > work_mem='64MB' (or even higher) before running the explain and see if it tries > a materialize. For situations like this where you're doing big one-off queries > you can afford to increase resource limits. None of 64MB, 128MB, 256MB and 512MB settings make a change in the query plan. Regards.