From: Frank Bax <fbax@sympatico.ca>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: jboes@nexcerpt.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Long-running DELETE...WHERE...
Date: Tue, 15 Jan 2002 14:22:50 -0500
Message-ID: <3.0.6.32.20020115142250.009b3970@pop6.sympatico.ca> (raw)
In-Reply-To: <21141.1011057670@sss.pgh.pa.us>
References: <d40a65a1.0201141027.6b15bc97@posting.google.com>
<d40a65a1.0201141027.6b15bc97@posting.google.com>
At 08:21 PM 1/14/02 -0500, Tom Lane wrote:
>jboes@nexcerpt.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
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: fbax@sympatico.ca, tgl@sss.pgh.pa.us, jboes@nexcerpt.com
Subject: Re: Long-running DELETE...WHERE...
In-Reply-To: <3.0.6.32.20020115142250.009b3970@pop6.sympatico.ca>
* 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