From: Pavel Stehule <pavel.stehule@gmail.com>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Adriaan van Os <postgres@microbizz.nl>
Cc: pgsql-performance@postgresql.org
Subject: Re: TRUNCATE TABLE
Date: Fri, 13 Jul 2007 21:12:34 +0200
Message-ID: <162867790707131212g17cbc5a9q5d098dbf01c8e502@mail.gmail.com> (raw)
In-Reply-To: <20070713173501.GD12109@alvh.no-ip.org>
References: <46953949.3030201@microbizz.nl>
<87ps2ypox3.fsf@oxford.xeocode.com>
<46972DFA.9000900@microbizz.nl>
<20070713124435.GL31358@mathom.us>
<21495.1184337630@sss.pgh.pa.us>
<4697A58E.8060904@microbizz.nl>
<23092.1184344246@sss.pgh.pa.us>
<20070713173501.GD12109@alvh.no-ip.org>
Hello,
I tested speed difference between TRUNCATE TABLE and DROP TABLE
(tested on my notebook ext3 and Linux fedora 7):
CREATE OR REPLACE FUNCTION test01() RETURNS SETOF double precision
AS $$
DECLARE t1 timestamp with time zone;
BEGIN
CREATE TEMP TABLE foo(a integer);
FOR i IN 1..1000 LOOP
INSERT INTO foo SELECT 1 FROM generate_series(1,10000);
t1 := clock_timestamp();
TRUNCATE TABLE foo;
RETURN NEXT EXTRACT('ms' FROM clock_timestamp()-t1);
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test02() RETURNS SETOF double precision
AS $$
DECLARE t1 timestamp with time zone;
BEGIN
FOR i IN 1..1000 LOOP
EXECUTE 'CREATE TEMP TABLE foo(a integer);';
EXECUTE 'INSERT INTO foo SELECT 1 FROM generate_series(1,10000);';
t1 := clock_timestamp();
EXECUTE 'DROP TABLE foo;';
RETURN NEXT EXTRACT('ms' FROM clock_timestamp()-t1);
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
vacuum pg_class; vacuum pg_type; vacuum pg_attribute;
postgres=# select count(*), min(t), max(t), avg(t), stddev_samp(t),
stddev_pop(t) from test01() t(t);
count | min | max | avg | stddev_samp | stddev_pop
-------+-------+---------+----------+------------------+------------------
1000 | 0.295 | 803.971 | 3.032483 | 30.0036729610037 | 29.9886673721876
(1 row)
Time: 33826,841 ms
postgres=# select count(*), min(t), max(t), avg(t), stddev_samp(t),
stddev_pop(t) from test02() t(t);
count | min | max | avg | stddev_samp | stddev_pop
-------+-------+--------+----------+------------------+-------------------
1000 | 0.418 | 20.792 | 0.619168 | 0.81550718804297 | 0.815099332459549
(1 row)
Time: 33568,818 ms
It's true, stddev_samp(TRUNCATE) >> stddev_samp(DROP)
Regards
Pavel Stehule
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: pavel.stehule@gmail.com, alvherre@commandprompt.com, tgl@sss.pgh.pa.us, postgres@microbizz.nl
Subject: Re: TRUNCATE TABLE
In-Reply-To: <162867790707131212g17cbc5a9q5d098dbf01c8e502@mail.gmail.com>
References: <46953949.3030201@microbizz.nl> <87ps2ypox3.fsf@oxford.xeocode.com> <46972DFA.9000900@microbizz.nl> <20070713124435.GL31358@mathom.us> <21495.1184337630@sss.pgh.pa.us> <4697A58E.8060904@microbizz.nl> <23092.1184344246@sss.pgh.pa.us> <20070713173501.GD12109@alvh.no-ip.org> <162867790707131212g17cbc5a9q5d098dbf01c8e502@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox