X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 85DBA9DC810 for ; Mon, 19 Dec 2005 10:47:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52716-02 for ; Mon, 19 Dec 2005 10:47:31 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.193]) by postgresql.org (Postfix) with ESMTP id EE2E89DC80C for ; Mon, 19 Dec 2005 10:47:23 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 14so1939141nzn for ; Mon, 19 Dec 2005 06:47:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=t1J5P6h3RM+Uikkpc23aLMDIubpM81FGVEdoj0mwtKXgQJeSGg6en1v6tMXX9ZXNDJBSX+GyOcp0wHO6ZDLO6hv28OeqOPb2OSO6M8mpJDeN9FOhbdvOd8MXb7f8lfPIG9Evjm7QrBwbNA3r8unL+rOdE82UmBbz5wGCHqVsHkg= Received: by 10.65.183.7 with SMTP id k7mr3027082qbp; Mon, 19 Dec 2005 06:47:27 -0800 (PST) Received: by 10.65.235.12 with HTTP; Mon, 19 Dec 2005 06:47:27 -0800 (PST) Message-ID: <8c8854360512190647q349c1ff2s63b05b218495bd04@mail.gmail.com> Date: Mon, 19 Dec 2005 22:47:27 +0800 From: Ang Chin Han To: James Klo Subject: Re: make bulk deletes faster? Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/454 X-Sequence-Number: 16275 On 12/18/05, James Klo wrote: > explain analyze delete from timeblock where timeblockid =3D 666666 > > Index Scan using timeblockid_idx on timeblock (cost=3D0.00..5.28 rows=3D= 1 > width=3D6) (actual time=3D0.022..0.022 rows=3D0 loops=3D1) > Index Cond: (timeblockid =3D 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.