Re: Boolean storage takes up 1 byte? - Mailing list pgsql-general

From Simon Riggs
Subject Re: Boolean storage takes up 1 byte?
Date
Msg-id 1254512544.4691.22.camel@ebony.2ndQuadrant
Whole thread Raw
In response to Re: Boolean storage takes up 1 byte?  (Sam Mason <sam@samason.me.uk>)
Responses Re: Boolean storage takes up 1 byte?
List pgsql-general
On Thu, 2009-10-01 at 12:03 +0100, Sam Mason wrote:

> > However, I see that a boolean takes up 1
> > byte of storage, which is 8 bits.  Is this due to the fact that the value
> > can be null?
>
> I believe it's more to do with the fact that if you add a boolean column
> and then subsequently an int column then you're going to struggle to
> "pack" them efficiently.  PG always puts columns on the "end" so that you
> can add a column in constant time (i.e. no need to rewrite the table
> in some common situations).  Once you start doing this then packing is
> awkward and a single byte becomes much easier.  Whether the value is
> NULL is stored elsewhere in the row.

It might be possible to make BOOLEAN NOT NULL use the null bit to
represent the actual data value and then have the column use no
additional bytes, except when we don't store the null bitmap at all.
Just needs people to make it happen cleanly, if that's possible.

Don't like booleans myself. They tend to end up as 3+ values eventually.

--
 Simon Riggs           www.2ndQuadrant.com


pgsql-general by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Time Management - Training Seminar in Cape Town
Next
From: Simon Riggs
Date:
Subject: Re: PostgreSQL reads each 8k block - no larger blocks are used - even on sequential scans