Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id D768F9FB614 for ; Mon, 16 Apr 2007 15:24:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 98725-03-3 for ; Mon, 16 Apr 2007 15:24:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 109729FB422 for ; Mon, 16 Apr 2007 15:24:18 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id F19D930952; Mon, 16 Apr 2007 20:24:16 +0200 (MET DST) From: Ron Mayer X-Newsgroups: pgsql.performance Subject: Re: Basic Q on superfluous primary keys Date: Mon, 16 Apr 2007 11:24:15 -0700 Organization: Hub.Org Networking Services Lines: 45 Message-ID: <4623BF4F.5070308@cheapcomplexdevices.com> References: <20070414075947.e5fbeec8.wmoran@collaborativefusion.com> <46239000.7000708@modgraph-usa.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org To: "Craig A. James" User-Agent: Icedove 1.5.0.10 (X11/20070329) In-Reply-To: <46239000.7000708@modgraph-usa.com> To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/318 X-Sequence-Number: 24195 Craig A. James wrote: > Merlin Moncure wrote: >> Using surrogate keys is dangerous and can lead to very bad design >> habits that are unfortunately so prevalent in the software industry >> they are virtually taught in schools. ... While there is >> nothing wrong with them in principle (you are exchanging one key for >> another as a performance optimization), they make it all too easy to >> create denormalized designs and tables with no real identifying >> criteria, etc,... > > Wow, that's the opposite of everything I've ever been taught, and all my > experience in the last few decades. > > ...chemistry...two companies using the same "natural" > keys had as much as 10% differences in their multi-million-compound > databases. These errors led to six-month to year-long delays, as each > of the conflicting chemical record had to be examined by hand by a PhD > chemist to reclassify it. That sounds almost like a feature, not a bug - giving information about what assumptions that went into the "natural key" need to be reconsidered. And I don't see how it would have been improved by adding a surrogate key - except that the data would have been just as messed up though harder to see where the messups were. > We've always recommended to our customers that all primary keys be > completely information free. They should be not based on any > information or combination of information from the data records. Every > time the customer has not followed this advice, they've later regretted it. Hmm... but then do you put a unique index on what the otherwise-would-have-been-natural-primary-key columns? If not, you tend to get into the odd situation of multiple rows that only vary in their surrogate key -- and it seems the surrogate key is redundant. > I'm sure there are situations where a natural key is appropriate, but I > haven't seen it in my work. I've seen both - and indeed usually use surrogate keys for convenience; but also find that having to fix incorrect assumptions in natural primary keys tends to raise business issues that are worth addressing anyway.