Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A786D17A3628 for ; Wed, 11 Jul 2012 11:06:03 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoxYI-0005GV-4A for pgsql-performance@postgresql.org; Wed, 11 Jul 2012 14:06:03 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6BE5mcv023854; Wed, 11 Jul 2012 10:05:49 -0400 (EDT) From: Tom Lane To: Daniel Farina cc: Craig Ringer , "pgsql-performance@postgresql.org" Subject: Re: DELETE vs TRUNCATE explanation In-reply-to: References: <4FFCCAC4.4030503@ringerc.id.au> Comments: In-reply-to Daniel Farina message dated "Tue, 10 Jul 2012 22:22:27 -0700" Date: Wed, 11 Jul 2012 10:05:48 -0400 Message-ID: <23853.1342015548@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/132 X-Sequence-Number: 47313 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