Re: enum for performance? - Mailing list pgsql-performance

From Tom Lane
Subject Re: enum for performance?
Date
Msg-id 5090.1245276728@sss.pgh.pa.us
Whole thread Raw
In response to enum for performance?  (Whit Armstrong <armstrong.whit@gmail.com>)
List pgsql-performance
Whit Armstrong <armstrong.whit@gmail.com> writes:
> I have a column which only has six states or values.
> Is there a size advantage to using an enum for this data type?
> Currently I have it defined as a character(1).

Nope.  enums are always 4 bytes.  char(1) is going to take 2 bytes
(assuming those six values are simple ASCII characters), at least
as of PG 8.3 or later.

Depending on what the adjacent columns are, the enum might not actually
cost you anything --- the difference might well disappear into alignment
padding anyway.  But it's not going to save.

Another possibility is to look at the "char" (not char) type, which also
stores single ASCII-only characters.  That's just one byte.  But again,
it might well not save you anything, depending on alignment
considerations.

            regards, tom lane

pgsql-performance by date:

Previous
From: Whit Armstrong
Date:
Subject: enum for performance?
Next
From: Tom Lane
Date:
Subject: Re: very slow selects on a small table