From: | Rod Taylor <pg(at)rbt(dot)ca> |
---|---|
To: | David Clarke <pigwin32(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Table design question |
Date: | 2006-06-01 13:41:56 |
Message-ID: | 1149169316.851.782.camel@home |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> So I'm designing a table and I'm looking for an appropriate key. The
> natural key is a string from a few characters up to a maximum of
> perhaps 100. Joe gets quite fierce about avoiding the use of a serial
> id column as a key. The string is unique in the table and fits the
> criteria for a key. So should I follow Joe's advice and use my natural
> key as the primary key? It sounds reasonable but it will mean at least
> one other table will have the string as a foreign key. My postgres
Unfortunately as a result of the implementation of most commercial
databases (and PostgreSQL), using a string as the primary key will cause
a performance hit.
Yes, normally it is better and for things like status flags and other
constant values that rarely change it is a good approach.
I would tend to add a SERIAL and make it the primary key (using it in
foreign tables) but also making the string column unique and not
null'able.
Essentially it gives the table two primary keys in the hope that some
day PostgreSQL will add a layer of abstraction between primary/foreign
key lookups and presentation that allows for usage of strings directly
without a performance hit.
--
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2006-06-01 13:53:10 | Re: SELECT DISTINCT too slow |
Previous Message | Miroslav Šulc | 2006-06-01 13:26:09 | SELECT DISTINCT too slow |