Re: Primary Keys

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Nabil Sayegh <postgresql(at)e-trolley(dot)de>, Farid Khan <Farid(dot)Khan(at)rogers(dot)com>, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Primary Keys
Date: 2003-11-09 21:33:47
Message-ID: 200311091333.47091.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Nabil, Farid,

> Personally I would always choose an extra SERIAL column.
> I don't really like the concept of having multiple columns as a PK.

I really have to disagree with you; if the real key of the table is two
numeric columns, then make that the primary key unless you can demonstrate
significant performance or application development problems.

For one thing, a serial column adds another 4 bytes per row to the table, and
overhead on inserts. It also raises the possibility of duplicate columns
X,Y; and if you put a unique index on X,Y, why bother with the surrogate key
at all?

I've a lot of tables with SERIAL surrogate keys, but those exist only for 3
reasons:
1) The real key involves several columns, including text and dates, that would
be a real query-writing hassle and/or potential performance-killer on joins;
2) Or where my web programmer refuses to deal with non-numeric keys (which he
frequently does ...)
3) The values of the key in existing rows is expected to change frequently and
there are FK-dependant tables (cascading updates are another
performance-killer).

Where none of those conditions apply, I use real keys.

--
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2003-11-09 22:08:54 Re: The data directory was initialized by PostgreSQL version 7.4, which is not compatible with this version 7.3.3.
Previous Message Nabil Sayegh 2003-11-09 20:22:42 Re: Primary Keys