pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedstring PK vs. interger PK
4+ messages / 4 participants
[nested] [flat]
* string PK vs. interger PK
@ 2002-04-15 18:56 Jodi Kanter <jkanter@virginia.edu>
2002-04-15 19:20 ` Re: string PK vs. interger PK Nick Fankhauser <nickf@ontko.com>
2002-04-15 19:51 ` Re: string PK vs. interger PK Marc Mitchell <marcm@eisolution.com>
2002-04-15 20:02 ` Re: string PK vs. interger PK Dan Langille <dan@langille.org>
0 siblings, 3 replies; 4+ messages in thread
From: Jodi Kanter @ 2002-04-15 18:56 UTC (permalink / raw)
To: pgsql-admin
Can anyone offer some insight as to what should be considered when choosing between a primary key that is an integer vs. a primary key that is a string value? Does one or the other affect indexing speed? update speed?
Is a serial integer value better than using a PK that has some "value" in its meaning but is a string?
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: string PK vs. interger PK
2002-04-15 18:56 string PK vs. interger PK Jodi Kanter <jkanter@virginia.edu>
@ 2002-04-15 19:20 ` Nick Fankhauser <nickf@ontko.com>
2 siblings, 0 replies; 4+ messages in thread
From: Nick Fankhauser @ 2002-04-15 19:20 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; pgsql-admin
As a general rule, a primary key (or any relationship key) should not
contain a value that means something beyond its use in relating entities.
The problem is that if a field describes an object, the day may come when
you want to change the description, but you *never* want to change the field
that identifies the record and relates it to other records.
I can't offer insider's knowledge on speed of int vs string, but it seems
very reasonable to think that an int would be faster. On the other hand, I'm
forced to use strings in my app, and the performance doesn't suffer much so
they must be close.
-Nick
--------------------------------------------------------------------------
Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/
-----Original Message-----
From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Jodi Kanter
Sent: Monday, April 15, 2002 1:56 PM
To: Postgres Admin List
Subject: [ADMIN] string PK vs. interger PK
Can anyone offer some insight as to what should be considered when choosing
between a primary key that is an integer vs. a primary key that is a string
value? Does one or the other affect indexing speed? update speed?
Is a serial integer value better than using a PK that has some "value" in
its meaning but is a string?
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: string PK vs. interger PK
2002-04-15 18:56 string PK vs. interger PK Jodi Kanter <jkanter@virginia.edu>
@ 2002-04-15 19:51 ` Marc Mitchell <marcm@eisolution.com>
2 siblings, 0 replies; 4+ messages in thread
From: Marc Mitchell @ 2002-04-15 19:51 UTC (permalink / raw)
To: Jodi Kanter <jkanter@virginia.edu>; pgsql-admin
Jodi:
This opinion has less to do with Postgres and more to do will a general
philosophy but we always use a 4 byte integer column as the primary key for
almost every table. None of the following reasons means it has to be that
way, but all support Ints over strings:
1) Strings would normally be bigger than 4 byte integers. While I have no
experience to say this size issue could contribute to a perceived
performance issue, theoretically speaking, a smaller, more compact value
would be better.
2) Int processing of equality and inequality comparisons should be much
faster than string compares. However, again I have no experience to say
this size issue could contribute to a perceived performance issue.
3) Ints make it easier to employ Postgres Sequences in generating PK
values. These are very nice and quick.
4) Lastly, I'll just agree with the other replies that I've already seen
that you should avoid putting any kind of meaningful data into PK columns.
That fact that you want to consider strings almost implies meaning to the
values. For example, if these values are dictated by an outside source
which happened to use an alphanumeric value, then they carry meaning to an
outside source even if that meaning is that it is simply their own unique
identifier.
We've been faced with this question many a time. We almost always chose an
int PK and more often than not when we've strayed from this course, it's
come back to haunt us.
Hope this is helpful.
Marc Mitchell - Senior Application Architect
Enterprise Information Solutions, Inc.
4910 Main Street
Downers Grove, IL 60515
(630) 512-0570
marcm@eisolution.com
----- Original Message -----
From: "Jodi Kanter" <jkanter@virginia.edu>
To: "Postgres Admin List" <pgsql-admin@postgresql.org>
Sent: Monday, April 15, 2002 1:56 PM
Subject: [ADMIN] string PK vs. interger PK
Can anyone offer some insight as to what should be considered when choosing
between a primary key that is an integer vs. a primary key that is a string
value? Does one or the other affect indexing speed? update speed?
Is a serial integer value better than using a PK that has some "value" in
its meaning but is a string?
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: string PK vs. interger PK
2002-04-15 18:56 string PK vs. interger PK Jodi Kanter <jkanter@virginia.edu>
@ 2002-04-15 20:02 ` Dan Langille <dan@langille.org>
2 siblings, 0 replies; 4+ messages in thread
From: Dan Langille @ 2002-04-15 20:02 UTC (permalink / raw)
To: pgsql-admin
On 15 Apr 2002 at 14:20, Nick Fankhauser wrote:
> As a general rule, a primary key (or any relationship key) should not
> contain a value that means something beyond its use in relating entities.
> The problem is that if a field describes an object, the day may come when
> you want to change the description, but you *never* want to change the
> field that identifies the record and relates it to other records.
FWIW, I would recommend not using business values as a primary key (and by
extension, as a foreign key). Business values are just that: business
values. Sure, put unique constraints on business values if you want.
Just don't make them a primary key or a foreign key.
--
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-04-15 20:02 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-15 18:56 string PK vs. interger PK Jodi Kanter <jkanter@virginia.edu>
2002-04-15 19:20 ` Nick Fankhauser <nickf@ontko.com>
2002-04-15 19:51 ` Marc Mitchell <marcm@eisolution.com>
2002-04-15 20:02 ` Dan Langille <dan@langille.org>
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