Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 9EDCC9FB2A4 for ; Wed, 18 Apr 2007 21:16:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 96396-03 for ; Wed, 18 Apr 2007 21:16:20 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.175]) by postgresql.org (Postfix) with ESMTP id 8E29B9FA603 for ; Wed, 18 Apr 2007 21:16:20 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id k3so421144ugf for ; Wed, 18 Apr 2007 17:16:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=p1KVoRhixNlUW1gs0JhclN8iqJLGi/EicTWXvAlilTAIFGS7IevQ5YG/DPyzxQPDPXV/2ua+u8Tg5Mb8iWuoow7mWDarBMRrbbmAqs529xevYBoV3fpmsCMxSJt+ykDB2js1P1IoMs7KNR1ACR+TwWUl3bU8OzdmRB5z1APiToI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=G67nABTt+VnXy8llAjP7xpFhP1S1q7KebTc+DjhQii2z5JOZfRyDHOXWQwC2roGAYQFInvHu6gmynLvZDdCFvfRVhkwJKKQA/OkjnhGZ5yFnvOZxLyix+S/S0LqU7A2goj3t5csx0R2MuXCf8qFw2Rtrswi7z2mczVmUUGrpCQ8= Received: by 10.78.171.13 with SMTP id t13mr171492hue.1176941778780; Wed, 18 Apr 2007 17:16:18 -0700 (PDT) Received: by 10.78.56.7 with HTTP; Wed, 18 Apr 2007 17:16:18 -0700 (PDT) Message-ID: Date: Thu, 19 Apr 2007 05:46:18 +0530 From: "Merlin Moncure" To: "Dave Dutcher" Subject: Re: Basic Q on superfluous primary keys Cc: pgsql-performance@postgresql.org In-Reply-To: <01db01c781e4$c700bf30$2e00a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <01db01c781e4$c700bf30$2e00a8c0@tridecap.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/342 X-Sequence-Number: 24219 On 4/18/07, Dave Dutcher 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