Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 2C7FEF6332B for ; Thu, 19 Jul 2012 11:52:52 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Srs5z-0005Jd-FW for pgsql-sql@postgresql.org; Thu, 19 Jul 2012 14:52:51 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6JEqZw6021290; Thu, 19 Jul 2012 10:52:35 -0400 (EDT) From: Tom Lane To: Thomas Kellerer cc: pgsql-sql@postgresql.org Subject: Re: DELETE using an outer join In-reply-to: References: Comments: In-reply-to Thomas Kellerer message dated "Thu, 19 Jul 2012 14:43:46 +0200" Date: Thu, 19 Jul 2012 10:52:34 -0400 Message-ID: <21289.1342709554@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/21 X-Sequence-Number: 36758 Thomas Kellerer writes: > Lately I had some queries of the form: > select t.* > from some_table t > where t.id not in (select some_id from some_other_table); > I could improve the performance of them drastically by changing the NOT NULL into an outer join: > select t.* > from some_table t > left join some_other_table ot on ot.id = t.id > where ot.id is null; If you're using a reasonably recent version of PG, replacing the NOT IN by a NOT EXISTS test should also help. > Now I was wondering if a DELETE statement could be rewritten with the same "strategy": Not at the moment. There have been discussions of allowing the same table name to be respecified in USING, but there are complications. regards, tom lane