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 0EB9AD1B386 for ; Tue, 20 Jul 2004 09:16:25 -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 59956-06 for ; Tue, 20 Jul 2004 12:16:19 +0000 (GMT) Received: from web11.manitu.net (web11.manitu.net [217.11.48.111]) by svr1.postgresql.org (Postfix) with ESMTP id EF938D1B2E0 for ; Tue, 20 Jul 2004 09:16:14 -0300 (ADT) Received: from [62.165.4.166] (dicaprio.akademie1.de [62.165.4.166]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id i6KCG9f09530 for ; Tue, 20 Jul 2004 14:16:09 +0200 Subject: surrogate key or not? From: Markus Bertheau To: pgsql-sql@postgresql.org Content-Type: text/plain Message-Id: <1090325769.3241.27.camel@dicaprio.akademie1.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 (1.4.5-7) Date: Tue, 20 Jul 2004 14:16:09 +0200 Content-Transfer-Encoding: 7bit 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/124 X-Sequence-Number: 18376 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