Re: unsigned types

Поиск
Список
Период
Сортировка
От Jim C. Nasby
Тема Re: unsigned types
Дата
Msg-id 20051017172518.GZ86144@pervasive.com
обсуждение исходный текст
Ответ на Re: unsigned types  (Jeff Davis <jdavis-pgsql@empires.org>)
Ответы Re: unsigned types  (Neil Conway <neilc@samurai.com>)
Список pgsql-general
On Sun, Oct 16, 2005 at 10:08:41AM -0700, Jeff Davis wrote:
> jeff sacksteder wrote:
> >
> >The sign doesn't concern me. I am storing a value that is unsigned and 16
> >bits wide natively. I'll have to just use an int4 and waste twice the space
> >I actually need.
> >
>
> Are you sure you'd really save space with a 16 bit type? Often times
> that savings gets lost in alignment.
>
> As far as I know, the smallest type that PostgreSQL supports is 4 bytes.
> On 64-bit architectures, it may be effectively 8 bytes (although I'm not
> sure about that).

It depends on MAXALIGN, which is 4 bytes on most platforms. But, there's
more to the story than that... If you SELECT typname, typalign FROM
pg_type WHERE typname LIKE 'int%'; you'll see that int2 can actually
align on smallint (typically 2 byte) boundaries. So, if you have a bunch
of int2's all next to each other in a table, they will happily just
consume 2 bytes. The issue comes when you try and mix them with other
fields randomly, since many other fields require int alignment.

Also, your suggestion of packing could actually hurt, since it will be
forced to an 8 byte boundary on most systems (int8 requires 'double'
alignment). If you instead used 4 smallint fields, all together, you
would probably only waste 2 bytes. Of course, this is all 100% dependant
on the other fields in the table.
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

В списке pgsql-general по дате отправления:

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: [pgsql-advocacy] Oracle buys Innobase
Следующее
От: "Dean Gibson (DB Administrator)"
Дата:
Сообщение: Re: Planner regression in 8.0.x: WORKAROUND