Re: VARCHAR -vs- CHAR: huge performance difference?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "C(dot) Bensend" <benny(at)bennyvision(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: VARCHAR -vs- CHAR: huge performance difference?
Date: 2004-06-16 02:07:49
Message-ID: 15549.1087351669@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"C. Bensend" <benny(at)bennyvision(dot)com> writes:
> So, I went ahead and created an exact copy of this table, with the
> exception of creating all character columns as type char(), not varchar().
> I was pondering if making PostgreSQL worry about the varying lengths
> by using varchar was the problem...

The above transformation is a guaranteed loser in Postgres.

> And sure enough, counting the rows on the new table takes around
> 148ms. That's a pretty big difference from 3600ms.

I'm betting that the original table is physically huge because you've
not vacuumed it regularly. The copying produced a table with no wasted
space, so physically smaller even though the live data is noticeably
bigger (because of all the padding blanks you forced to be added).

Check what VACUUM VERBOSE has to say about each of these tables...

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message C. Bensend 2004-06-16 02:12:29 Re: VARCHAR -vs- CHAR: huge performance difference?
Previous Message Tom Lane 2004-06-16 01:39:23 Re: Out of memory error