surrogate key or not?

From: Markus Bertheau <twanger(at)bluetwanger(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: surrogate key or not?
Date: 2004-07-20 12:16:09
Message-ID: 1090325769.3241.27.camel@dicaprio.akademie1.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 <twanger(at)bluetwanger(dot)de>

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Lars Erik Thorsplass 2004-07-20 13:34:20 Stored procedures and "pseudo" fields..
Previous Message Lars Erik Thorsplass 2004-07-20 10:43:30 Stored procedures and "pseudo" fields..