Re: DELETE vs TRUNCATE explanation - Mailing list pgsql-performance

From Daniel Farina
Subject Re: DELETE vs TRUNCATE explanation
Date
Msg-id CAAZKuFZ9tYeC1K5ZayZgztm3re_7ytbsEYFa0wwXirB6Hfm+EQ@mail.gmail.com
Whole thread Raw
In response to DELETE vs TRUNCATE explanation  (Craig Ringer <ringerc@ringerc.id.au>)
Responses Re: DELETE vs TRUNCATE explanation
Re: DELETE vs TRUNCATE explanation
List pgsql-performance
On Tue, Jul 10, 2012 at 5:37 PM, Craig Ringer <ringerc@ringerc.id.au> wrote:
> Hi
>
> After seeing a few discussions here and on Stack Overflow I've put together
> a quick explanation of why "DELETE FROM table;" may be faster than "TRUNCATE
> table" for people doing unit testing on lots of tiny tables, people who're
> doing this so often they care how long it takes.
>
> I'd love it if a few folks who know the guts were to take a look and verify
> its correctness:

I haven't said this before, but think it every time someone asks me
about this, so I'll say it now:

This is a papercut that should be solved with improved mechanics.
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?

--
fdr

pgsql-performance by date:

Previous
From: Craig Ringer
Date:
Subject: DELETE vs TRUNCATE explanation
Next
From: Yan Chunlu
Date:
Subject: Re: how could select id=xx so slow?