Re: Boolean storage takes up 1 byte?

Поиск
Список
Период
Сортировка
От Simon Riggs
Тема Re: Boolean storage takes up 1 byte?
Дата
Msg-id 1254512544.4691.22.camel@ebony.2ndQuadrant
обсуждение исходный текст
Ответ на Re: Boolean storage takes up 1 byte?  (Sam Mason <sam@samason.me.uk>)
Ответы Re: Boolean storage takes up 1 byte?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Time Management - Training Seminar in Cape Town
Следующее
От: Simon Riggs
Дата:
Сообщение: Re: PostgreSQL reads each 8k block - no larger blocks are used - even on sequential scans