TRUNCATE veeeery slow compared to DELETE in 7.4

From: Hartmut Raschick <hartmut(dot)raschick(at)ke-elektronik(dot)de>
To: pgsql-performance(at)postgresql(dot)org
Subject: TRUNCATE veeeery slow compared to DELETE in 7.4
Date: 2003-12-08 14:03:34
Message-ID: 3FD484B6.EF39A92F@ke-elektronik.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

has anyone else noticed a huge difference in "DELETE TABLE <lol>"
vs. "TRUNCATE <lol>" starting w/postgres 7.4?
putting aside details (num rows, indexes....): ca. 300 tables
(already empty if desired...) ALL to be emptied (via batch file).
here's a small "time pgsql -f kill_all" output:

DELETE:
1) 0.03u 0.04s 0:02.46 2.8% (already empty)
2) 0.05u 0.06s 0:01.19 9.2% (already empty)

TRUNCATE:
1) 0.10u 0.06s 6:58.66 0.0% (already empty, compile runnig simult.)
2) 0.10u 0.02s 2:51.71 0.0% (already empty)

lovely, innit?

settings in 7.4 (wal, shm...) are as for 7.3.x unless dead or (in their
7.4 default version) even higher.

glimpsing at the quantify output (of the truncate version) it looks
as if this is "for (i = 0; i < all; i++)" whereas (from exec. time)
delete does "\rm -rf"

is this a pay-off for autocommit gone away?
a conspiracy?
...what am i saying...

we are using TRUNCATE btw, because someone once noted that this was
"good style", saying: "yes, i want to empty the whole thing", not:
"oops! forgot the where-clause, sorry for your table!"

well, enlight me, please!

P.S.: Grammarians dispute - and the case is still before the courts.
- Horace, Epistles (Ars Poetica)

--
Hartmut "Hardy" Raschick / Dept. t2
ke Kommunikations-Elektronik GmbH
Wohlenberstr. 3, 30179 Hannover
Phone: ++49 (0)511 6747-564
Fax: ++49 (0)511 6747-340
e-Mail: hartmut(dot)raschick(at)ke-elektronik(dot)de
http://www.ke-elektronik.de

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Steve Wampler 2003-12-08 15:14:53 Re: Help tracking down problem with inserts slowing
Previous Message Matthew T. O'Connor 2003-12-08 05:27:29 Re: autovacuum daemon stops doing work after about an hour