Search Postgresql Archives

Re: unsigned types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux