Re: best way to query

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Steve Clark" <sclark(at)netwolves(dot)com>
Cc: "pgsql" <pgsql-general(at)postgresql(dot)org>
Subject: Re: best way to query
Date: 2008-01-25 16:50:41
Message-ID: c2253cb4-fe3b-4f6a-8040-ab9c9b44c757@mm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steve Clark wrote:

> any way i have 2 table - A and B.
> each table has a key field and if a row is in B it should have a
> corresponding row in A - but theres
> the problem it doesn't for all the rows in B.
>
> So I want to do something like
> delete from B where key not in (select key from A order by key);
>
> The problem is there are about 1,000,000 rows in A and 300,000 rows
in
> B. I let the above run
> all night and it was still running the next morning. Does anyone have

> an idea of a better way.

An outer join is sometimes spectacularly more efficient for this
particular kind of query.

I'd suggest you try:

delete from B where key in
(select B.key from B left outer join A on A.key=B.key
where A.key is null)

--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message johnf 2008-01-25 16:51:47 Re: exporting postgre data
Previous Message Steve Clark 2008-01-25 16:23:51 Re: best way to query