From: Adriaan van Os <postgres@microbizz.nl>
To: pgsql-performance@postgresql.org
Subject: Re: TRUNCATE TABLE
Date: Thu, 12 Jul 2007 09:37:40 +0200
Message-ID: <4695DA44.2060000@microbizz.nl> (raw)
In-Reply-To: <3561.1184190885@sss.pgh.pa.us>
References: <46953949.3030201@microbizz.nl>
<3561.1184190885@sss.pgh.pa.us>
Gregory Stark wrote:
> That's strange. Deleting should be the *quickest* operation in Postgres. Do
> you perchance have foreign key references referencing this table?
No.
> Do you have any triggers?
No.
Tom Lane wrote:
> Adriaan van Os <postgres@microbizz.nl> writes:
>> Surprisingly, one of the bottlenecks is TRUNCATE TABLE and that
>> command is really slow as compared to other operations.
>
> When you don't quantify that statement at all, it's hard to make an
> intelligent comment on it, but TRUNCATE per se shouldn't be slow.
> Are you sure you are not measuring a delay to obtain exclusive lock
> on the table before it can be truncated (ie, waiting for other
> transactions to finish with it)?
During the tests, there is only one connection to the database server. No other transactions are
running.
> When you don't quantify that statement at all, it's hard to make an
> intelligent comment on it, but TRUNCATE per se shouldn't be slow.
Below are some timings, in milliseconds.
> TRUNCATE TABLE my_temporary_table
> COPY my_temporary_table ... FROM STDIN BINARY
> do_something
The temporary table has one INT4 field and no indices.
Numrows TRUNCATE (ms) COPY (ms) SELECT (ms)
5122 80,6 16,1 51,2
3910 79,5 12,9 39,9
2745 90,4 10,7 32,4
1568 99,5 7,6 24,7
398 161,1 4,0 22,1
200 79,5 3,3 22,0
200 87,9 3,1 22,0
222368 4943,5 728,6 7659,5
222368 1685,7 512,2 2883,1
Note how fast the COPY is (which is nice). The SELECT statement uses the temporary table.
Regards,
Adriaan van Os
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: postgres@microbizz.nl
Subject: Re: TRUNCATE TABLE
In-Reply-To: <4695DA44.2060000@microbizz.nl>
* 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