Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id F25A79FC13D for ; Fri, 13 Jul 2007 16:12:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63958-03 for ; Fri, 13 Jul 2007 16:12:35 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.225]) by postgresql.org (Postfix) with ESMTP id B92F09FC130 for ; Fri, 13 Jul 2007 16:12:40 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id 68so427841wri for ; Fri, 13 Jul 2007 12:12:34 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZJeR+szWFp+UNTgIHmYDvXaqajFxSp17QAHd49LzGQ7cqg+TIlIgCozicpYXHFLRVZAhKTiLr0/0P4Qcu3SM/OACk0RLkxFetovoGA5bt6wKlohk0U3WiyM7OtCb+6MPBOilxCEBdqGIYCsEWR5u+vxI/rsa1m8Yow3sys/qEE8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=l1OY5JvXF+DJMx27rYgFzRjTWTVPyKSXbtprmy2iZV45v3XocehExlLNuEDsR0zwY+h+5Z3zigoG1I4DxgUvU47NZ/uBb6BvALHo+BchyGvRskxgAZK3IL0AwxkQTMl3PUmkTLalfpSiCjALCSoq0Ju/NKJLJewM9JWaflq/oNM= Received: by 10.143.16.9 with SMTP id t9mr149960wfi.1184353954155; Fri, 13 Jul 2007 12:12:34 -0700 (PDT) Received: by 10.142.80.10 with HTTP; Fri, 13 Jul 2007 12:12:34 -0700 (PDT) Message-ID: <162867790707131212g17cbc5a9q5d098dbf01c8e502@mail.gmail.com> Date: Fri, 13 Jul 2007 21:12:34 +0200 From: "Pavel Stehule" To: "Alvaro Herrera" Subject: Re: TRUNCATE TABLE Cc: "Tom Lane" , "Adriaan van Os" , pgsql-performance@postgresql.org In-Reply-To: <20070713173501.GD12109@alvh.no-ip.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/164 X-Sequence-Number: 25848 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