Re: efficient deletes on subqueries

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "postgresql" <postgres(at)lg(dot)ndirect(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: efficient deletes on subqueries
Date: 2001-10-30 16:48:33
Message-ID: 20895.1004460513@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"postgresql" <postgres(at)lg(dot)ndirect(dot)co(dot)uk> writes:
> I want to remove all entries from AA where keyA matches that from
> obsolete_AA_entries,
> i.e. SELECT * FROM AA NATURAL JOIN obsolete_AA_entries;

> DELETE FROM AA WHERE EXISTS(
> SELECT * from obsolete_AA_entries o where AA.keyA = o.keyA);
> seems to be faster than
> DELETE FROM AA where (keyA) in (SELECT * from obsolete_AA_entries);

> However, both are sequentially going through AA which is huge rather than
> looking up values one by one from obsolete_AA_entries which is small.
> How do I persuade the database to change its query strategy?

Try
DELETE FROM AA WHERE AA.keyA = obsolete_AA_entries.keyA;

This is not valid SQL according to the SQL standard, but Postgres takes
it anyway.

Turning sub-SELECT queries into plannable joins is on the todo list,
but it's not done yet :-(

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jochem van Dieten 2001-10-30 17:01:30 Re: SQL99
Previous Message postgresql 2001-10-30 15:33:05 efficient deletes on subqueries