pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: DELETE using an outer join
Date: Thu, 19 Jul 2012 10:52:34 -0400
Message-ID: <21289.1342709554@sss.pgh.pa.us> (raw)
In-Reply-To: <ju8veb$dkn$1@dough.gmane.org>
References: <ju8veb$dkn$1@dough.gmane.org>

Thomas Kellerer <spam_eater@gmx.net> 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



view thread (9+ messages)  latest in thread

Message-ID: <21289.1342709554@sss.pgh.pa.us>
Permalink:  ../21289.1342709554@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21289.1342709554@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, spam_eater@gmx.net
  Subject: Re: DELETE using an outer join
  In-Reply-To: <21289.1342709554@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox