Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 6AB4617A3628 for ; Wed, 11 Jul 2012 11:20:08 -0300 (ADT) Received: from mh2.mail.rice.edu ([128.42.201.21]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Soxlv-0005T2-83 for pgsql-performance@postgresql.org; Wed, 11 Jul 2012 14:20:07 +0000 Received: from mh2.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh2.mail.rice.edu (Postfix) with ESMTP id B132D11F86A; Wed, 11 Jul 2012 09:19:54 -0500 (CDT) Received: from mh2.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh2.mail.rice.edu (Postfix) with ESMTP id 6CD5911F867; Wed, 11 Jul 2012 09:19:54 -0500 (CDT) X-Virus-Scanned: by amavis-2.7.0 at mh2.mail.rice.edu, auth channel Received: from mh2.mail.rice.edu ([127.0.0.1]) by mh2.mail.rice.edu (mh2.mail.rice.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id mm2_Met9qvem; Wed, 11 Jul 2012 09:19:54 -0500 (CDT) X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh2.mail.rice.edu (Postfix) with ESMTP id 1D4D311F85F; Wed, 11 Jul 2012 09:19:54 -0500 (CDT) Received: by aart.rice.edu (Postfix, from userid 18612) id B36E81005A3; Wed, 11 Jul 2012 09:19:54 -0500 (CDT) Date: Wed, 11 Jul 2012 09:19:54 -0500 From: "ktm@rice.edu" To: Tom Lane Cc: Daniel Farina , Craig Ringer , "pgsql-performance@postgresql.org" Subject: Re: DELETE vs TRUNCATE explanation Message-ID: <20120711141954.GJ15829@aart.rice.edu> References: <4FFCCAC4.4030503@ringerc.id.au> <23853.1342015548@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <23853.1342015548@sss.pgh.pa.us> User-Agent: Mutt/1.5.20 (2009-12-10) X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201207/133 X-Sequence-Number: 47314 On Wed, Jul 11, 2012 at 10:05:48AM -0400, Tom Lane wrote: > Daniel Farina writes: > > TRUNCATE should simply be very nearly the fastest way to remove data > > from a table while retaining its type information, and if that means > > doing DELETE without triggers when the table is small, then it should. > > The only person who could thwart me is someone who badly wants their > > 128K table to be exactly 8 or 0K, which seems unlikely given the 5MB > > of catalog anyway. > > > Does that sound reasonable? As in, would anyone object if TRUNCATE > > learned this behavior? > > Yes, I will push back on that. > > (1) We don't need the extra complexity. > > (2) I don't believe that you know where the performance crossover point > would be (according to what metric, anyway?). > > (3) The performance of the truncation itself should not be viewed in > isolation; subsequent behavior also needs to be considered. An example > of possible degradation is that index bloat would no longer be > guaranteed to be cleaned up over a series of repeated truncations. > (You might argue that if the table is small then the indexes couldn't > be very bloated, but I don't think that holds up over a long series.) > > IOW, I think it's fine as-is. I'd certainly wish to see many more > than one complainant before we expend effort in this area. > > regards, tom lane > +1 TRUNCATE needs to keep the same properties independent of the size of the table. Smearing it into a DELETE would not be good at all. If there are optimizations that can be done to keep its current behavior, those might be possible, but the complexity may not be worthwhile for a relative corner case. Regards, Ken