pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ed L. <pgsql@bluepolka.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORMANCE] slow small delete on large table
Date: Tue, 24 Feb 2004 11:36:08 -0700
Message-ID: <200402241136.08556.pgsql@bluepolka.net> (raw)
In-Reply-To: <18315.1077600238@sss.pgh.pa.us>
References: <200402231910.57078.pgsql@bluepolka.net>
	<18315.1077600238@sss.pgh.pa.us>

On Monday February 23 2004 10:23, Tom Lane wrote:
> "Ed L." <pgsql@bluepolka.net> writes:
> > If I could say it the way I think for a simple example, it'd be
> > like this:
> >
> > 	delete from mytable
> > 	where posteddatetime < now() - '90 days'
> > 	limit 100;
> >
> > Of course, that's not legal 7.3.4 syntax.
>
> Assuming you have a primary key on the table, consider this:
>
> CREATE TEMP TABLE doomed AS
>   SELECT key FROM mytable WHERE posteddatetime < now() - '90 days'
>   LIMIT 100;
>
> DELETE FROM mytable WHERE key = doomed.key;
>
> DROP TABLE doomed;
>
> Depending on the size of mytable, you might need an "ANALYZE doomed"
> in there, but I'm suspecting not.  A quick experiment suggests that
> you'll get a plan with an inner indexscan on mytable.key, which is
> exactly what you need.

I didn't mention I'd written a trigger to do delete N rows on each new 
insert (with a delay governor preventing deletion avalanches).  The 
approach looks a little heavy to be done from within a trigger with the 
response time I need, but I'll try it.  Cantchajust toss in that "limit N" 
functionality to delete clauses?  How hard could that be?  ;)

> See also Chris Browne's excellent suggestions nearby, if you are willing
> to make larger readjustments in your thinking...

I did a search for articles by Chris Browne, didn't see one that appeared 
relevant.  What is the thread subject to which you refer?




view thread (7+ messages)  latest in thread

Message-ID: <200402241136.08556.pgsql@bluepolka.net>
Permalink:  ../200402241136.08556.pgsql@bluepolka.net/
Also on:    postgresql.org/message-id/200402241136.08556.pgsql@bluepolka.net

 · 

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-performance@postgresql.org
  Cc: pgsql@bluepolka.net, tgl@sss.pgh.pa.us
  Subject: Re: [PERFORMANCE] slow small delete on large table
  In-Reply-To: <200402241136.08556.pgsql@bluepolka.net>

* 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