pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: josh@agliodbs.com
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Cc: Alexandre Leclerc <alexandre.leclerc@gmail.com>
Subject: Re: Data type to use for primary key
Date: Mon, 22 Nov 2004 20:03:11 -0500
Message-ID: <1101171791.44437.7.camel@home> (raw)
In-Reply-To: <200411221654.56673.josh@agliodbs.com>
References: <1dc7f0e30411221232603c4617@mail.gmail.com>
	<200411221654.56673.josh@agliodbs.com>

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.


-- 




view thread (14+ messages)  latest in thread

Message-ID: <1101171791.44437.7.camel@home>
Permalink:  ../1101171791.44437.7.camel@home/
Also on:    postgresql.org/message-id/1101171791.44437.7.camel@home

 · 

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: pg@rbt.ca, josh@agliodbs.com, alexandre.leclerc@gmail.com
  Subject: Re: Data type to use for primary key
  In-Reply-To: <1101171791.44437.7.camel@home>

* 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