Re: Avoiding surrogate keys - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Avoiding surrogate keys
Date
Msg-id 20100421194324.GB3762@alvh.no-ip.org
Whole thread Raw
In response to Re: Avoiding surrogate keys  (Bill Moran <wmoran@potentialtech.com>)
List pgsql-general
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 space -- wrong,
> an int is 4 bytes, but a 2 byte char column is 1/2 that ... even if the
> number never gets higher than 50.

Eh, a 2 byte char column uses 3 bytes -- there's one byte of overhead.
(Unless one of the chars is multibyte in which case it can be longer).
Earlier versions of Postgres use 6 bytes to store the 2 chars (4 bytes
of overhead), so it would be larger than the int.

Not that this invalidates the argument -- just nitpicking here.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-general by date:

Previous
From: Bill Moran
Date:
Subject: Re: Avoiding surrogate keys
Next
From: Merlin Moncure
Date:
Subject: Re: Avoiding surrogate keys