Re: [GENERAL] Avoiding surrogate keys

2010-05-04 Thread Grzegorz Jaśkiewicz
the rule of thumb for me is: - if you have more than one column as PK - and are variable length, or more than 2 columns, fixed length, no bigger than 8 bytes - go for surrogate - always. - if PK is variable length, on average longer than 8 bytes, or can change - go surrogate. - Otherwise leave

Re: [GENERAL] Avoiding surrogate keys

2010-05-04 Thread Richard Broersma
2010/5/4 Grzegorz Jaśkiewicz : > > Another thing, If your PK changes, it is no longer a PK, you can't rely on it. Depending upon what you mean by changes this could be true or it could be a matter of opinion. If your referring to a candidate key's value changes, this key still provides a useful w

Re: [GENERAL] Avoiding surrogate keys

2010-05-04 Thread Grzegorz Jaśkiewicz
On Tue, May 4, 2010 at 3:16 PM, Merlin Moncure wrote: > On Tue, May 4, 2010 at 9:40 AM, Merlin Moncure wrote: >> On Sat, May 1, 2010 at 4:14 PM, John R Pierce wrote: >>> >>> If your 'natural key' is a large text field, I'd have to assume there's some >>> point at which a surrogate index would be

Re: [GENERAL] Avoiding surrogate keys

2010-05-04 Thread Merlin Moncure
On Tue, May 4, 2010 at 9:40 AM, Merlin Moncure wrote: > On Sat, May 1, 2010 at 4:14 PM, John R Pierce wrote: >> >> If your 'natural key' is a large text field, I'd have to assume there's some >> point at which a surrogate index would be more efficient.  Would this be >> above a few dozen characte

Re: [GENERAL] Avoiding surrogate keys

2010-05-04 Thread Merlin Moncure
On Sat, May 1, 2010 at 4:14 PM, John R Pierce wrote: > > If your 'natural key' is a large text field, I'd have to assume there's some > point at which a surrogate index would be more efficient.  Would this be > above a few dozen characters, or a few 100 characters?   I wouldn't want a > PK based o

Re: [GENERAL] Avoiding surrogate keys

2010-05-01 Thread John R Pierce
If your 'natural key' is a large text field, I'd have to assume there's some point at which a surrogate index would be more efficient. Would this be above a few dozen characters, or a few 100 characters? I wouldn't want a PK based on a multi-K byte text field for a table that has many 10s

Re: [GENERAL] Avoiding surrogate keys

2010-05-01 Thread Merlin Moncure
On Sat, May 1, 2010 at 12:09 PM, Lew wrote: > Philippe Lang wrote: >> >> I think nobody mentioned Object-Relational mappers. >> If you intend to used one (or think you may be using one in the future), >> using surrogate keys is more straightforward, if not necessary. > > Neither of those claims is

Re: [GENERAL] Avoiding surrogate keys

2010-05-01 Thread Lew
Philippe Lang wrote: I think nobody mentioned Object-Relational mappers. If you intend to used one (or think you may be using one in the future), using surrogate keys is more straightforward, if not necessary. Neither of those claims is even slightly true. Using Hibernate, EclipseLink or Ope

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Philippe Lang
Hi, I think nobody mentioned Object-Relational mappers. If you intend to used one (or think you may be using one in the future), using surrogate keys is more straightforward, if not necessary. Best regards, - Attik System

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Mark Watson
nvoyé : 21 avril 2010 16:38 À : wmo...@potentialtech.com Cc : pgsql-general@postgresql.org Objet : Re: [GENERAL] Avoiding surrogate keys ... static information such as country names *should be* de-normalised into non-indexed columns of the driving table as you have already done if on the other hand

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Martin Gainty
.com > CC: pgsql-general@postgresql.org > Subject: Re: [GENERAL] Avoiding surrogate keys > > In response to Thom Brown : > > > I think I know what I plan to do, but want to throw this out there to see if > > there are differing points of view. > > > > I have a maili

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Merlin Moncure
On Wed, Apr 21, 2010 at 3:32 PM, Bill Moran wrote: > In response to "Joshua D. Drake" : > >> On Wed, 2010-04-21 at 15:07 -0400, Bill Moran wrote: >> > I'd use an ENUM for the status, as that's not liable to change. >> > >> > The only problem I see with avoiding the surrogate key for the country >>

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Alvaro Herrera
Bill Moran escribió: > One thing that a lot of people seem to get confused about is that they > subconsciously think that ints or bigints take up less space when the > numbers are small. I.e.: I want to use an int for my state identifier > instead of the 2-digit code, because it will use less spa

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Bill Moran
In response to "Joshua D. Drake" : > On Wed, 2010-04-21 at 15:07 -0400, Bill Moran wrote: > > I'd use an ENUM for the status, as that's not liable to change. > > > > The only problem I see with avoiding the surrogate key for the country > > is that the table might require more disk space if a lot

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Thom Brown
On 21 April 2010 20:18, Merlin Moncure wrote: > On Wed, Apr 21, 2010 at 3:01 PM, Thom Brown wrote: > > I think I know what I plan to do, but want to throw this out there to see > if > > there are differing points of view. > > I have a mailing list table, and 2 of the columns contain values which

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Joshua D. Drake
On Wed, 2010-04-21 at 15:18 -0400, Merlin Moncure wrote: > Natural keys: > *) force formal relationships into your key design (this is good) > *) Make your database MUCH easier to follow, browse, and understand > *) in particular cases allow you to skip joins > *) will make your indexes fatter (th

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Merlin Moncure
On Wed, Apr 21, 2010 at 3:01 PM, Thom Brown wrote: > I think I know what I plan to do, but want to throw this out there to see if > there are differing points of view. > I have a mailing list table, and 2 of the columns contain values which have > to be from a list.  These are country and status.

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Rich Shepard
On Wed, 21 Apr 2010, Thom Brown wrote: I have a mailing list table, and 2 of the columns contain values which have to be from a list. Thom, From 2 lists? These are country and status. And each is from a separate list, correct? There are 237 possible countries and 3 possible statuses

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Joshua D. Drake
On Wed, 2010-04-21 at 15:07 -0400, Bill Moran wrote: > I'd use an ENUM for the status, as that's not liable to change. > > The only problem I see with avoiding the surrogate key for the country > is that the table might require more disk space if a lot of the country > names end up being very long

Re: [GENERAL] Avoiding surrogate keys

2010-04-21 Thread Bill Moran
In response to Thom Brown : > I think I know what I plan to do, but want to throw this out there to see if > there are differing points of view. > > I have a mailing list table, and 2 of the columns contain values which have > to be from a list. These are country and status. There are 237 possi