X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 06FD7D1C4EE for ; Sat, 2 Aug 2003 00:22:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 81956-08 for ; Fri, 1 Aug 2003 21:20:56 -0300 (ADT) Received: from frmug.org (frmug-gw.frmug.org [193.56.58.252]) by svr1.postgresql.org (Postfix) with ESMTP id 73E5AD1C4BD for ; Fri, 1 Aug 2003 21:21:59 -0300 (ADT) Received: from frmug.org (localhost [127.0.0.1]) by frmug.org (8.12.9/8.11.3/frmug-2.7/nospam) with ESMTP id h720M2Xd078343 (using TLSv1/SSLv3 with cipher DHE-RSA-AES256-SHA (256 bits) verified NO) for ; Sat, 2 Aug 2003 02:22:02 +0200 (CEST) (envelope-from pgsql-sql@phoe.frmug.org) Received: (from uucp@localhost) by frmug.org (8.12.9/8.12.9/Submit) with UUCP id h720M293078342 for pgsql-sql@postgresql.org; Sat, 2 Aug 2003 02:22:02 +0200 (CEST) Received: (from elrond@localhost) by memo.frmug.org (8.11.6/8.11.6) id h720Lrr86132 for pgsql-sql@postgresql.org; Sat, 2 Aug 2003 02:21:53 +0200 (CEST) (envelope-from pgsql-sql@memo.frmug.org) X-Authentication-Warning: memo.frmug.org: elrond set sender to pgsql-sql@memo.frmug.org using -f Date: Sat, 2 Aug 2003 02:21:52 +0200 From: Bertrand Petit To: pgsql-sql@postgresql.org Subject: Efficient deletions? Message-ID: <20030802022152.A86089@memo.frmug.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/21 X-Sequence-Number: 14637 Hello, This is my first message to this list. I'm curently trying to improve my postgres skillsm I've assigned myself a project involving a database whose dataset is quite larger than those I had to use until now. I'm curently facing a trouble with the DELETE query: I need to delete from a table a set of rows choosen by a sub-select. The query curently looks like this: DELETE FROM foo WHERE (col1, col2) IN (SELECT...) It seems from the output of ANALYSE that the sub-query is executed for each foo rows. That's really not efficient as the set returned by the sub-select is constant. I had a similar trouble with a SELECT query but it was eavily solved by placing one of the sub-select in the FROM part of the query. Unfortunately it look that can't be done this way with DELETE. Is there a way to instruct the planner that this sub-query is constant over the time of the DELETE execution? Or is there another more efficent way to express this? I conducted tests with a sub-select returning about 20,000 rows and a foo table of 370,000 rows, out of patience I had to interrupt the query after five hours. That worries me as this query is part of an update process that could be fired several times a day. -- %!PS 297.6 420.9 translate 90 rotate 0 setgray gsave 0 1 1{pop 0 180 moveto 100 180 170 100 170 -10 curveto 180 -9 180 -9 190 -10 curveto 190 100 100 180 0 180 curveto fill 180 rotate}for grestore/Bookman-LightItalic findfont 240 scalefont setfont -151.536392 -63.7998886 moveto (bp)show showpage