pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: C. Bensend <benny@bennyvision.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: VARCHAR -vs- CHAR: huge performance difference?
Date: Tue, 15 Jun 2004 22:51:52 -0400
Message-ID: <15996.1087354312@sss.pgh.pa.us> (raw)
In-Reply-To: <50124.63.227.74.41.1087351971.squirrel@webmail.stinkweasel.net>
References: <51429.63.227.74.41.1087347504.squirrel@webmail.stinkweasel.net>
	<15549.1087351669@sss.pgh.pa.us>
	<50124.63.227.74.41.1087351971.squirrel@webmail.stinkweasel.net>

"C. Bensend" <benny@bennyvision.com> writes:
>> The above transformation is a guaranteed loser in Postgres.

>    By transformation, do you mean the varchar() -> char() change?

Right.  The only thing that will do for you is waste space with padding
blanks.  The performance improvement you saw was due to something else,
which I theorize is not having to waste time reading dead space.

Since you obviously doubt this assertion, try the same experiment except
load the data into a new table with the *same* structure as the original
(ie, all varchar).  You'll see the same or probably better performance.

> Actually, all databases on this server are vacuumed nightly, right
> before backups.

Not often enough evidently...

> INFO:  --Relation public.emails--
> INFO:  Pages 5793: Changed 0, Empty 0; Tup 24198: Vac 82, Keep 0, UnUsed
> 71757.

> INFO:  --Relation public.emails2--
> INFO:  Pages 2646: Changed 0, Empty 0; Tup 24162: Vac 0, Keep 0, UnUsed 0.

Note the difference in "pages".  emails is nearly double the physical
size, even though the live data in it is doubtless smaller.  (You could
use the contrib/pgstattuple functions to see exactly how much live data
there is.)

I was actually expecting to see more than a 2:1 difference in file size,
seeing that you reported more than a 2:1 difference in read time.  It
could be that there is also some question of physical layout of the file
on disk.  The original table probably accreted over time and was given
space that's not very consecutive on disk.  The copied table was
written in one swoop, more or less, and is very likely stored in a more
nearly consecutive set of physical disk blocks.  I'm not sure how you'd
investigate this theory though --- AFAIK there isn't any real easy way
to find out how badly fragmented a file is in most Unix filesystems.

			regards, tom lane



view thread (18+ messages)  latest in thread

Message-ID: <15996.1087354312@sss.pgh.pa.us>
Permalink:  ../15996.1087354312@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15996.1087354312@sss.pgh.pa.us

 · 

reply

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, benny@bennyvision.com
  Subject: Re: VARCHAR -vs- CHAR: huge performance difference?
  In-Reply-To: <15996.1087354312@sss.pgh.pa.us>
  References: <51429.63.227.74.41.1087347504.squirrel@webmail.stinkweasel.net> <15549.1087351669@sss.pgh.pa.us> <50124.63.227.74.41.1087351971.squirrel@webmail.stinkweasel.net> <15996.1087354312@sss.pgh.pa.us>

* 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