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

"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.

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

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <18315.1077600238@sss.pgh.pa.us>
Permalink:  ../18315.1077600238@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18315.1077600238@sss.pgh.pa.us

 · 

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

* 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