storage size of "bitstring"?

Started by Alex Mayrhoferover 19 years ago2 messagesgeneral
Jump to latest
#1Alex Mayrhofer
axelm@nona.net

Hi,

Two short questions:

1) What storage size does the "bit(n)" data type have? Is it one byte per 8
bits (plus a "length" byte)? I didn't find this in neither the docs nor the
list archives ...

2) Additionally, how much storage space does a functional index which
returns "boolean" approx. take? Will it be a bitmap?

Reason: i need to add some flags to a row, and i don't want to spend an
entire byte per flag on a "boolean" column (even worse, new flags could
probably be added in the future) - would it make sense to use
a bitstring, together with a functional index on any "interesting" bit in
that case?

thanks,

Alex

#2Martijn van Oosterhout
kleptog@svana.org
In reply to: Alex Mayrhofer (#1)
Re: storage size of "bitstring"?

On Sun, Oct 22, 2006 at 06:24:43PM +0200, Alex Mayrhofer wrote:

Hi,

Two short questions:

1) What storage size does the "bit(n)" data type have? Is it one byte per 8
bits (plus a "length" byte)? I didn't find this in neither the docs nor the
list archives ...

It'll be a varlena structure, see backend/utils/adt/varbit.c. So 4
bytes + space needed for bits.

2) Additionally, how much storage space does a functional index which
returns "boolean" approx. take? Will it be a bitmap?

A boolean is one byte, plus whatever overhead is associated with the
index.

Reason: i need to add some flags to a row, and i don't want to spend an
entire byte per flag on a "boolean" column (even worse, new flags could
probably be added in the future) - would it make sense to use
a bitstring, together with a functional index on any "interesting" bit in
that case?

I'd say give it a shot. Seems reasonable.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

From each according to his ability. To each according to his ability to litigate.