pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ed L. <pgsql@bluepolka.net>
To: pgsql-performance@postgresql.org
Subject: [PERFORMANCE]  slow small delete on large table
Date: Mon, 23 Feb 2004 19:10:57 -0700
Message-ID: <200402231910.57078.pgsql@bluepolka.net> (raw)


A 7.3.4 question...

I want to "expire" some data after 90 days, but not delete too
much at once so as not to overwhelm a system with precariously
balanced disk I/O and on a table with millions of rows.  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.  These are both too
slow due to sequential scan of table:

	delete from mytable where key in (
		select key
		from mytable
		where posteddatetime < now() - '90 days'
		limit 100);
or 
	delete from mytable where exists (
		select m.key
		from mytable m
		where m.key = mytable.key
		  and m.posteddatetime < now() - '90 days'
		limit 100);

Tried to use a cursor, but couldn't figure out the syntax
for select-for-delete yet, or find appropriate example on
google.  Any clues?

TIA.




view thread (7+ messages)  latest in thread

Message-ID: <200402231910.57078.pgsql@bluepolka.net>
Permalink:  ../200402231910.57078.pgsql@bluepolka.net/
Also on:    postgresql.org/message-id/200402231910.57078.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
  Subject: Re: [PERFORMANCE]  slow small delete on large table
  In-Reply-To: <200402231910.57078.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