X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id F3E5ED1B4CE for ; Mon, 15 Dec 2003 18:22:17 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 88066-06 for ; Mon, 15 Dec 2003 14:21:55 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id CD1D8D1DCDA for ; Mon, 15 Dec 2003 14:21:48 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id hBFILl19013899; Mon, 15 Dec 2003 13:21:48 -0500 (EST) To: Hartmut Raschick Cc: pgsql-performance@postgresql.org, Rod Taylor Subject: Re: TRUNCATE veeeery slow compared to DELETE in 7.4 In-reply-to: <3FD99CDA.8161D80A@ke-elektronik.de> References: <3FD484B6.EF39A92F@ke-elektronik.de> <200312100918.02501.josh@agliodbs.com> <8000.1071086054@sss.pgh.pa.us> <3FD99CDA.8161D80A@ke-elektronik.de> Comments: In-reply-to Hartmut Raschick message dated "Fri, 12 Dec 2003 11:47:54 +0100" Date: Mon, 15 Dec 2003 13:21:47 -0500 Message-ID: <13898.1071512507@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/228 X-Sequence-Number: 5088 Hartmut Raschick writes: > [ TRUNCATE is much slower in 7.4 than in 7.3 ] After looking into this, I think this is because when Rod Taylor reimplemented TRUNCATE to make it transaction-safe, he essentially turned it into a variant of CLUSTER. It is slow because it is creating and deleting dummy tables and indexes. I think this is not really necessary and it could be done better while still being transaction-safe. All we really need is to create a new empty table file, update the table's pg_class row with the new relfilenode, mark the old file for deletion, and then run REINDEX TABLE (which will perform similar shenanigans with the indexes). regards, tom lane