Re: enum for performance?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Whit Armstrong <armstrong(dot)whit(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: enum for performance?
Date: 2009-06-17 22:12:08
Message-ID: 5090.1245276728@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Whit Armstrong <armstrong(dot)whit(at)gmail(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2009-06-17 22:29:29 Re: very slow selects on a small table
Previous Message Whit Armstrong 2009-06-17 22:06:06 enum for performance?