From: Merlin Moncure <mmoncure@gmail.com>
To: Dave Dutcher <dave@tridecap.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Basic Q on superfluous primary keys
Date: Thu, 19 Apr 2007 05:46:18 +0530
Message-ID: <b42b73150704181716wb1600aey8761b6793d3fd702@mail.gmail.com> (raw)
In-Reply-To: <01db01c781e4$c700bf30$2e00a8c0@tridecap.com>
References: <b42b73150704170917n33ebcdc8wc852a3fa02fd8bb5@mail.gmail.com>
<01db01c781e4$c700bf30$2e00a8c0@tridecap.com>
On 4/18/07, Dave Dutcher <dave@tridecap.com> wrote:
> I think a database with all natural keys is unrealistic. For example if you
> have a table that refers to people, are you going to use their name as a
> primary key? Names change all the time due to things like marriage,
> divorce, or trouble with the law. We have tables with 20 million rows which
> reference back to a table of people, and if I used the person's name as key,
> it would be a major pain when somebody's name changes. Even if there is
> referential integrity, one person might be referred to by 25% of the 20
> million rows, so the update would take quite a long time. Also the table
> will be filled with dead rows and the indexes will likely be bloated. If I
> want to clean that up, it will take a vacuum full or a cluster which will
> lock the whole table and run for hours. If I use a surrogate key, I can
> change their name in one row and be done with it.
That's perfectly reasonable (I mentioned this upthread)...there are a
couple of corner cases where RI costs too much Exchanging a surrogate
for a natural is a valid performance consideration. Usually, the
performance win is marginal at best (and your example suggests
possible normalization issues in the child table), sometimes there is
no alternative....updating 5 million rows is obviously nasty. That
said -- if the cost of update was zero, would you still do it that
way? I'm trying to separate performance related issues, which are
reasonable and valid depending on the situation, with good design
principles.
merlin
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: mmoncure@gmail.com, dave@tridecap.com
Subject: Re: Basic Q on superfluous primary keys
In-Reply-To: <b42b73150704181716wb1600aey8761b6793d3fd702@mail.gmail.com>
References: <b42b73150704170917n33ebcdc8wc852a3fa02fd8bb5@mail.gmail.com> <01db01c781e4$c700bf30$2e00a8c0@tridecap.com> <b42b73150704181716wb1600aey8761b6793d3fd702@mail.gmail.com>
* 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