pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Bertheau <twanger@bluetwanger.de>
To: pgsql-sql@postgresql.org
Subject: surrogate key or not?
Date: Tue, 20 Jul 2004 14:16:09 +0200
Message-ID: <1090325769.3241.27.camel@dicaprio.akademie1.de> (raw)

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@bluetwanger.de>




view thread (44+ messages)  latest in thread

Message-ID: <1090325769.3241.27.camel@dicaprio.akademie1.de>
Permalink:  ../1090325769.3241.27.camel@dicaprio.akademie1.de/
Also on:    postgresql.org/message-id/1090325769.3241.27.camel@dicaprio.akademie1.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: twanger@bluetwanger.de
  Subject: Re: surrogate key or not?
  In-Reply-To: <1090325769.3241.27.camel@dicaprio.akademie1.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox