pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ang Chin Han <ang.chin.han@gmail.com>
To: James Klo <jklo@arkitec.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: make bulk deletes faster?
Date: Mon, 19 Dec 2005 22:47:27 +0800
Message-ID: <8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com> (raw)
In-Reply-To: <jklo-C7336F.21104017122005@news.hub.org>
References: <jklo-C7336F.21104017122005@news.hub.org>

On 12/18/05, James Klo <jklo@arkitec.com> wrote:
> explain analyze delete from timeblock where timeblockid = 666666
>
> Index Scan using timeblockid_idx on timeblock  (cost=0.00..5.28 rows=1
> width=6) (actual time=0.022..0.022 rows=0 loops=1)
>   Index Cond: (timeblockid = 666666)
> Total runtime: 0.069 ms
... snip ...
> Here's what I've tried:
>
> Attempt 1:
> ----------
> delete from timeblock where timeblockid in (select timeblockid from
> timeblock_tmp)

The DELETE in Attempt 1 contains a join, so if this is the way you're
mainly specifying which rows to delete, you'll have to take into
account how efficient the join of timeblock and timeblock_tmp is. What
does

EXPLAIN ANALYZE select * from timeblock where timeblockid in (select
timeblockid from timeblock_tmp)

or

EXPLAIN ANALYZE delete from timeblock where timeblockid in (select
timeblockid from timeblock_tmp)

say?

You *should* at least get a "Hash IN join" for the outer loop, and
just one Seq scan on timeblock_tmp. Otherwise, consider increasing
your sort_mem (postgresql 7.x) or work_mem (postgresql 8.x) settings.
Another alternative is to reduce the amount of rows being archive at
one go to fit in the amount of sort_mem or work_mem that allows the
"Hash IN Join" plan. See
http://www.postgresql.org/docs/8.1/static/runtime-config-resource.html#GUC-WORK-MEM

On the other hand, PostgreSQL 8.1's partitioning sounds like a better
long term solution that you might want to look into.



view thread (7+ messages)  latest in thread

Message-ID: <8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com>
Permalink:  ../8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com/
Also on:    postgresql.org/message-id/8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com

 · 

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-performance@postgresql.org
  Cc: ang.chin.han@gmail.com, jklo@arkitec.com
  Subject: Re: make bulk deletes faster?
  In-Reply-To: <8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com>
  References: <jklo-C7336F.21104017122005@news.hub.org> <8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com>

* 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