Re: Primary Key Performance with INTEGER vs. VARCHAR

From: Jim Nasby <decibel(at)decibel(dot)org>
To: Siah <siasookhteh(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Primary Key Performance with INTEGER vs. VARCHAR
Date: 2007-07-24 18:47:28
Message-ID: 5A03DE8B-8FF6-4CFE-95AD-D9019437462C@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jul 21, 2007, at 5:49 AM, Siah wrote:
> Designing my application, I was wondering if having my primary keys
> (to be indexed) with VARCHAR brings performance down significantly? My
> own test didn't show much difference. Thinking about it though, I'd
> guess Integer Indexing should be much quicker and efficient.

Generally, anything dealing with a text/varchar field is going to be
slower than on, say, an integer. But remember the first rule of
performance tuning: don't. Do you *really* need to worry about the
extra overhead of varchar vs int? Probably not.

What you *should* be thinking about is do you really want a varchar
PK? Generally speaking, it's better to use a phantom PK (ie: a
SERIAL), and put a UNIQUE constraint on the varchar in the
appropriate table.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2007-07-24 18:48:20 Re: postgresql compile problem
Previous Message Jim Nasby 2007-07-24 18:41:34 Re: Best interval timeout and check interval for Slony