pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pgsql-sql@ruby.sartorelli.gen.nz
To: pgsql-sql@hub.org
Subject: Problem with SQL query (eats swap)
Date: Fri, 11 Aug 2000 14:46:21 +1200 (NZST)
Message-ID: <m13N4px-003bmOC@ruby.sartorelli.gen.nz> (raw)

Hi, I have two tables into which I dump mail statistics.  The two tables are:

create table attachments (
  id text,
  attachment text
);
create table mail (
  id text,
  size int,
  whofrom text,
  subject text,
  date datetime,
  inout char
);

The table mail holds information about each mail message.  The table attachments holds the name of any attachments.  Linking the attachment(s) and the message is the id.

I want to delete all records relating to mail that is over two months old.  I tried:

select count(*) from attachments a where a.id in (select m.id from mail m where m.date < now()-62);

but ran out of swap.  The mail table is 19Mb, the attachment one 1Mb.  I was up to 380Mb of swap used on a machine with 128Mb RAM, and over 15 minutes run time.  At that point I killed the query.

I next tried is as follows:

drop table temp;
select id into temp from mail where date < now()-62;
delete from attachments where id in (select id from temp);
delete from mail where date < now()-62;

This worked fine and deleted the records as intended in a few minutes.  Can anyone see why the initial query ate so much swap?


Cheers
Kevin
kevin@sartorelli.gen.nz



view thread (2+ messages)  latest in thread

Message-ID: <m13N4px-003bmOC@ruby.sartorelli.gen.nz>
Permalink:  ../m13N4px-003bmOC@ruby.sartorelli.gen.nz/
Also on:    postgresql.org/message-id/m13N4px-003bmOC@ruby.sartorelli.gen.nz

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pgsql-sql@ruby.sartorelli.gen.nz, pgsql-sql@hub.org
  Subject: Re: Problem with SQL query (eats swap)
  In-Reply-To: <m13N4px-003bmOC@ruby.sartorelli.gen.nz>
  References: <m13N4px-003bmOC@ruby.sartorelli.gen.nz>

* 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