From: | Simon Riggs <simon(at)2ndQuadrant(dot)com> |
---|---|
To: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Boolean storage takes up 1 byte? |
Date: | 2009-10-02 19:42:24 |
Message-ID: | 1254512544.4691.22.camel@ebony.2ndQuadrant |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2009-10-02 19:52:58 | Re: PostgreSQL reads each 8k block - no larger blocks are used - even on sequential scans |
Previous Message | Simon Riggs | 2009-10-02 19:32:50 | Re: Time Management - Training Seminar in Cape Town |