From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Saving bytes in custom data type |
Date: | 2011-03-16 18:29:02 |
Message-ID: | AANLkTim9kZDSbC+xrEkOrvkvfy69emAdFeYN05+pVZ6J@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Mar 16, 2011 at 12:19 PM, Daniele Varrazzo
<daniele(dot)varrazzo(at)gmail(dot)com> wrote:
> Hello,
>
> I'm writing a variable size custom datatype in C. The variable part is
> an array of unsigned long, and it needs to be aligned. I further need
> to store a few flags, for which a single byte would be more than
> enough (I would actually need just a single bit, but I'd probably keep
> some bits to store a data version too).
>
> Using a struct like
>
> {
> char vl_len_[4]; /* varlena header */
> unsigned char flags;
> unsigned long data[1];
> }
>
> 3 bytes are always wasted in padding as offsetof(data) is 8.
>
> I may complicate fetching a little bit and store the flags at the end
> of the data, so that the total size would be 5 + data instead of 8 +
> data, and access them with some pointers arithmetic.
>
> In terms of disk space, does it worth the hassle or (as I suspect)
> would this effort be wasted by on-disk alignment of the data in the
> rows?
question: if you are storing just flags and bytes, why not use a bytea
and store the flags out of line?
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2011-03-16 18:36:32 | Re: query taking much longer since Postgres 8.4 upgrade |
Previous Message | Tom Lane | 2011-03-16 17:29:33 | Re: converting E'C:\\something' to bytea |