X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1492AD1B220 for ; Tue, 20 Jul 2004 22:31:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27694-10 for ; Wed, 21 Jul 2004 01:31:12 +0000 (GMT) Received: from millenium.mst.co.jp (unknown [210.230.185.241]) by svr1.postgresql.org (Postfix) with ESMTP id 164BED1B1D1 for ; Tue, 20 Jul 2004 22:31:06 -0300 (ADT) Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i6L1V3t18508; Wed, 21 Jul 2004 10:31:03 +0900 Message-ID: <004101c46ec2$631ca930$7201a8c0@mst1x5r347kymb> From: "Iain" To: "Markus Bertheau" , References: <1090325769.3241.27.camel@dicaprio.akademie1.de> Subject: Re: surrogate key or not? Date: Wed, 21 Jul 2004 10:31:03 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/134 X-Sequence-Number: 18386 Hi, for my 2c worth, performance is the least important of the things you need to consider regarding use of surrogate keys. I use surrogate keys for all situations except the simplest code/description tables, and this is only when the code has no meaning to the application. If there is any possibility that you will want to update or re-use codes (attaching a different meaning to them) then surrogate keys are the way to go.. Thus I see it more as an issue of business logic than performance. There are of course many other considerations with relational theory and stuff like that which you could debate endlessly. I expect that googling on "surrogate keys" would yeild interesting results. Regards Iain ----- Original Message ----- From: "Markus Bertheau" To: Sent: Tuesday, July 20, 2004 9:16 PM Subject: [SQL] surrogate key or not? > Hi, > > I have a database that has types in them with unique names. These types > are referenced from other tables through a surrogate integer key. I'm > now wondering if I should eliminate that surrogate key and just use the > name as the primary key. Afaiu, surrogate keys are primarily there to > make joining tables or otherwise searching for a record faster, because > it's faster to compare two integers than it is to compare two strings. > > Now when I want to search for a type in types or another table that > references types(type_id), under what circumstances is it advisable to > have a surrogate integer key and not use the unique type name? Is > searching for an integer as fast as is searching for a string when both > have an index? How many records in the type table do I need to make a > surrogate key a not unsignificantly faster way to retrieve a row? What > about joins? Are these the right questions? > > Thanks. > > -- > Markus Bertheau > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org