Re: VARCHAR -vs- CHAR: huge performance difference? - Mailing list pgsql-admin

From Tom Lane
Subject Re: VARCHAR -vs- CHAR: huge performance difference?
Date
Msg-id 15549.1087351669@sss.pgh.pa.us
Whole thread Raw
In response to VARCHAR -vs- CHAR: huge performance difference?  ("C. Bensend" <benny@bennyvision.com>)
Responses Re: VARCHAR -vs- CHAR: huge performance difference?  ("C. Bensend" <benny@bennyvision.com>)
List pgsql-admin
"C. Bensend" <benny@bennyvision.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

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: Out of memory error
Next
From: "C. Bensend"
Date:
Subject: Re: VARCHAR -vs- CHAR: huge performance difference?