Skip site navigation (1) Skip section navigation (2)

Re: Data type to use for primary key

From: Rod Taylor <pg(at)rbt(dot)ca>
To: josh(at)agliodbs(dot)com
Cc: Postgresql Performance <pgsql-performance(at)postgresql(dot)org>,Alexandre Leclerc <alexandre(dot)leclerc(at)gmail(dot)com>
Subject: Re: Data type to use for primary key
Date: 2004-11-23 01:03:11
Message-ID: 1101171791.44437.7.camel@home (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
On Mon, 2004-11-22 at 16:54 -0800, Josh Berkus wrote:
> Alexandre,
> > What is the common approach? Should I use directly the product_code as
> > my ID, or use a sequantial number for speed? (I did the same for the
> > company_id, this is a 'serial' and not the shor name of the customer.
> > I just don't know what is usually done.
> Don't use SERIAL just because it's there.    Ideally, you *want* to use the 
> product_code if you can.   It's your natural key and a natural key is always 
> superior to a surrogate key all other things being equal.   

It would be nice if PostgreSQL had some form of transparent surrogate
keying in the background which would automatically run around and
replace your real data with SERIAL integers. It could use a lookup table
for conversions between the surrogate and real values so the user never
knows that it's done, a bit like ENUM. Then we could all use the real
values with no performance issues for 1) because it's an integer in the
background, and 2) because a cascade only touches a single tuple in the
lookup table.


In response to


pgsql-performance by date

Next:From: Bruce MomjianDate: 2004-11-23 02:18:05
Subject: Re: memcached and PostgreSQL
Previous:From: Josh BerkusDate: 2004-11-23 00:54:56
Subject: Re: Data type to use for primary key

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group