Re: Long-running DELETE...WHERE...

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: jboes(at)nexcerpt(dot)com (Jeff Boes), pgsql-sql(at)postgresql(dot)org
Subject: Re: Long-running DELETE...WHERE...
Date: 2002-01-15 19:22:50
Message-ID: 3.0.6.32.20020115142250.009b3970@pop6.sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 08:21 PM 1/14/02 -0500, Tom Lane wrote:
>jboes(at)nexcerpt(dot)com (Jeff Boes) writes:
>> My situation: table A has 200,000 rows. I've made up a temporary table
>> which holds the single-valued primary key for 80,000 rows which I want
>> to delete.
>> DELETE FROM a WHERE id IN (select ID from tmp LIMIT 800);
>> runs for several minutes.
>
>WHERE ... IN ... is notoriously inefficient. I'd try
>
> DELETE FROM aa WHERE id = tmp.id;
>
>which is not standard SQL but should be able to produce a decent plan.

Nice alternative. Is there an alternate format for this one:

DELETE FROM teamwork WHERE emp NOT IN
( SELECT DISTINCT emp FROM timesheet
WHERE lo_shift > (now()-'90days'::interval) )

Frank

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2002-01-16 05:13:49 Re: Long-running DELETE
Previous Message Josh Berkus 2002-01-15 19:10:05 Re: Problem with the postgresql operator.