pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Dawid Kuroczko <qnex42@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: best practices with index on varchar column
Date: Wed, 23 Mar 2005 11:31:28 +0000
Message-ID: <42415390.8030208@archonet.com> (raw)
In-Reply-To: <758d5e7f05032301351b685c44@mail.gmail.com>
References: <op.sn1ccygeth1vuj@localhost>
	<200503230402.j2N42ax1022249@mail.census.gov.ph>
	<758d5e7f05032301351b685c44@mail.gmail.com>

Dawid Kuroczko wrote:
> On Wed, 23 Mar 2005 12:11:56 +0800, Michael Ryan S. Puncia
> <mpuncia@census.gov.ph> wrote:
> 
>>I have an experience using LIKE in a VARCHAR column and select statement
>>suffers a lot so I decided to go back in CHAR

> According to the PostgreSQL's documentation:
> 
>      Tip: There are no performance differences between these three types,
> apart from the increased storage size when using the blank-padded type.
> While character(n) has performance advantages in some other database
> systems, it has no such advantages in PostgreSQL. In most situations text
> or character varying should be used instead.
> 
> 
> To my best knowledge char and varchar are stored in a same way
> (4-byte length plus textual value), so using char should make tables
> bigger in your case.  Then again, having each row exactly the same
> size makes it easier to delete and then later insert a new row in
> a same spot.  Am I thinking correct?  Is it a case where using char(n)
> makes that table avoid hmm fragmentation of some sort?

There aren't any noticeable differences between char and varchar. MVCC 
doesn't overwrite rows anyway, so static size is irrelevant. In any 
case, PG's toast setup splits out large text fields and compresses them 
- so it's not that simple.

-- 
   Richard Huxton
   Archonet Ltd



view thread (7+ messages)

Message-ID: <42415390.8030208@archonet.com>
Permalink:  ../42415390.8030208@archonet.com/
Also on:    postgresql.org/message-id/42415390.8030208@archonet.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, qnex42@gmail.com
  Subject: Re: best practices with index on varchar column
  In-Reply-To: <42415390.8030208@archonet.com>

* 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